Question

In: Computer Science

Can anyone just check my code and tell me why the program doesn't show the end...

Can anyone just check my code and tell me why the program doesn't show the end date & stops at the date before the end date? Tell me how i can fix it.

Question:

Write a program compare.cpp that asks the user to input two dates (the beginning and the end of the interval). The program should check each day in the interval and report which basin had higher elevation on that day by printing “East” or “West”, or print “Equal” if both basins are at the same level.

My code:

#include

#include

#include

#include

using namespace std;

int main()

{

string date;

string starting_date;

string ending_date;

double eastSt;

double eastEl;

double westSt;

double westEl;

int dateRange=0;

cout<< "Enter the starting date" << endl;

cin>> starting_date;

cout<< "Enter the ending date" << endl;

cin>> ending_date;

ifstream fin("Current_Reservoir_Levels.tsv");

if (fin.fail())

{

cerr << "File cannot be opened for reading." << endl;

exit(1);

}

string junk;

getline(fin, junk);

while(fin >> date >> eastSt >> eastEl >> westSt >> westEl)

{

fin.ignore(INT_MAX, '\n');

if (date == starting_date)

{

dateRange = 1;

}

if (date == ending_date)

{

dateRange= 0;

}

if (dateRange == 1)

{

if(eastEl > westEl)

{

cout<< date << " "<< "East " <

}

else if (eastEl < westEl)

{

cout<< date << " " << "West" <

}

else if (eastEl == westEl )

{

cout<< date << " " << "Equal" <

}

}

}

return 0;

}

Expected output

01/17/2018 West
  01/18/2018 West
  01/19/2018 West
  01/20/2018 West
  01/21/2018 West
  01/22/2018 West
  01/23/2018 West
Received output:
01/17/2018 West
  01/18/2018 West
  01/19/2018 West
  01/20/2018 West
  01/21/2018 West
  01/22/2018 West

*************** F.H**************

Solutions

Expert Solution

Explanation

you are following like if start data came in file u r assigning dataRange=1 and if end date came u r making it as dataRange=0 but problem you need to make this is after complition of printing end date string also i have move below code after displaying result.

if (date == ending_date)

{

dateRange= 0;

}

//CODE TO COPY


#include<iostream>
#include<string>
#include <fstream>
#include <cstdlib>
using namespace std;

int main()

{

string date;

string starting_date;

string ending_date;

double eastSt;

double eastEl;

double westSt;

double westEl;

int dateRange=0;

cout<< "Enter the starting date" << endl;

cin>> starting_date;

cout<< "Enter the ending date" << endl;

cin>> ending_date;

ifstream fin("Current_Reservoir_Levels.tsv");

if (fin.fail())

{

cerr << "File cannot be opened for reading." << endl;

exit(1);

}

string junk;

getline(fin, junk);

while(fin >> date >> eastSt >> eastEl >> westSt >> westEl)

{

fin.ignore(INT_MAX, '\n');

if (date == starting_date)

{

dateRange = 1;

}

if (dateRange == 1)

{

if(eastEl > westEl)

{

cout<< date << " "<< "East " <<endl;

}

else if (eastEl < westEl)

{

cout<< date << " " << "West" <<endl;

}

else if (eastEl == westEl )

{

cout<< date << " " << "Equal" <<endl;

}

}

if (date == ending_date)

{

dateRange= 0;

}

}

return 0;

}


Related Solutions

Hello Everyone, Can anyone tell me why my program will not run? I am trying to...
Hello Everyone, Can anyone tell me why my program will not run? I am trying to work on abstract base classes... not sure what is going on. import math from abc import ABC from abc import abstractmethod #TODO: convert this to an ABC class Shape(ABC): def __init__(self): self.name = "" def display(self): print("{} - {:.2f}".format(self.name, self.get_area())) #TODO: Add an abstractmethod here called get_area @abstractmethod def get_area(self): if self.name == "Circle": get_area()= 3.14 * radius * radius else: get_area() = self.length...
can anyone tell me the reason why if the number of basis is equal to the...
can anyone tell me the reason why if the number of basis is equal to the dimension of a vector space V then it is the basis of the vector space V. and also what the theorem is? since, I think if V=span{(1,0,0), (0,1,0)} and dim(V)=2 and basis={(1,0,0), (0,0,1)} which the number is also 2. but it is not the basis of V. So, can you tell where is the mistake. THANK YOU!
Can you please tell me why my code isn't working? It won't calculate the values I...
Can you please tell me why my code isn't working? It won't calculate the values I have using my input file. /******************************************************************************* AUTHOR SECTION ENGR 200.07 DATE: 10/23/2020 PROGRAM: ******************************************************************************** PROGRAM DESCRIPTION This program takes a pre-made .txt file’s input values, and calculates the kinetic energy wind farms produce from moving air into electrical energy. Using 3 different formulas this program calculates the available power in the wind, the maximum available power that can be produced, and the amount of...
Can anyone tell me about the measurement of ICP-AES?
Can anyone tell me about the measurement of ICP-AES?
I just wanted to double check my answers, can you just provide me with the correct...
I just wanted to double check my answers, can you just provide me with the correct answer for each one in order to cross-check, thank you. The United States' class system is heavily dependent upon an individual's social background. True False At which level of the factors which put women at risk does the following statement fit? "Tolerance of violence as a means of conflict resolution". Family/Relationship Level Individual Level Community Level Societal Level Which of the following countries is...
I just wanted to double check my answers, can you just provide me with the correct...
I just wanted to double check my answers, can you just provide me with the correct answer for each one in order to cross-check, thank you. When women carry the burden of poverty and are treated as non-equals when compared to men, which of the following terms describes this circumstance? Twice Burdened Double Discrimination Double Deprivation Double Jeopardy Which of the following countries was not a colony of Britain? Singapore Korea Hong Kong In 2012, which country utilized 2.8% of...
anyone can explain why this code in R doesn't work? i also tried to use filter...
anyone can explain why this code in R doesn't work? i also tried to use filter function, no hope either! b <- subset(sub,NEIGHBORHOOD == "HARLEM-CENTRAL") the name of the variable is correct, the condition. is correct too.
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------ class Robot{ int serialNumber; boolean flies,autonomous,teleoperated; public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated){ this.serialNumber = serialNumber; this.flies = flies; this.autonomous = autonomous; this.teleoperated = teleoperated; } public int getSerialNumber(){ return this.serialNumber; } public boolean canFly(){ return this.flies; } public boolean isAutonomous(){ return this.autonomous; } public boolean isTeleoperated(){ return this.teleoperated; } public String getCapabilities(){ StringBuilder str = new StringBuilder(); if(this.flies){str.append("canFly");str.append(" ");} if(this.autonomous){str.append("autonomous");str.append("...
Can someone tell me how to fix warning msg in my code of C ++? I...
Can someone tell me how to fix warning msg in my code of C ++? I got run-time error for this question please help me asap! Errors are: In function 'void bfs(int, int)': warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int j = 0; j < adj[pppp].size(); j++){ ^ In function 'int main()': warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d %d %d %d", &a, &q, &c, &N, &m); ^...
can someone finish and check my code on main. cpp? Its not working for me even...
can someone finish and check my code on main. cpp? Its not working for me even though im sure my code make sense is it possible to output each function to show they work. this is supposed to be a vector class library made from allocated memory i have included templated functions in the class file to help create the rest of the functions. Thank you so much note: i did not include main.cpp because it  was empty- im hoping someone...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT