You are here:

# C++/C++ program help error

Question
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{

char fare;
char choice='Y';
int hrIn, minIn, hrOut, minOut;
int hours;
int minutes;
int total_minutes;
double cost;
float charge;

while(choice=='Y'||choice=='y')
{
cout << "
This program will calculate a group "
<< "
fare amount which is then owed by the customer for the trip.
"
<< "
To calculate a group fare amount, input G (or g)"
<< "

Input G: ";
cin >> fare;

if(fare=='G'||fare=='g'){

cout << "
What hour did they depart? ";
cin >> hrOut;
cout << "
What minute did they depart? ";
cin >> minOut;
cout << "
You entered for departure: " << hrOut << ":" << minOut << endl;
cout << "
What hour did they arrive? ";
cin >> hrIn;
cout << "
What minute did they arrive? ";
cin >> minIn;
cout << "
You entered for arrival: " << hrIn << ":" << minIn << "
" << endl;
cout << "A rickshaw departed at " << hrOut << ":" << minOut
<< " and arrived at " << hrIn << ":" << minIn << " with a group of customers.
" << endl;

if(hrIn >= hrOut && minIn >= minOut){

hours = (hrIn - hrOut);
cout << "You arrived in " << hours << " hour(s)";
minutes = minIn - minOut;
cout << " and " << minutes << " minute(s) ";
total_minutes = (hours * 60) + minutes;
cout << ", or in a total of " << total_minutes << " minutes.
" << endl;
}
else{

hours = (hrIn - hrOut-1);
cout << "You arrived in " << hours << " hour(s)";
minutes = minIn - minOut+60;
cout << " and " << minutes << " minute(s) ";
total_minutes = (hours * 60) + minutes;
cout << ", or in a total of " << total_minutes << " minutes.
" << endl;
}

if(total_minutes <=15){

charge = 16.00;
cout << "You owe \$" << charge << " dollars.
" << endl;
}

if(total_minutes > 30){

charge = 16.00 + (((total_minutes) - 15) * 4.00) + 50;
cout << "You owe an additional amount of \$50.00 for exceeding 30 minutes,"
<< "
which brings your total amount to \$" << charge << " dollars.
" << endl;
}
if{15 < Total_minutes <= 30){

charge = 16.00 + (((total_minutes) - 15) * 4.00);
cout << "You owe \$" << charge << " dollars.
" << endl;

}
//------------------------------------…
else

cout << "
The character that you have entered is invalid. Please try again.
" << endl;

cout << "Would you like to perform another calculation (Y/N)? ";
cin >> choice;

}

cout << "
Thank you for using the ODUSPORTS calculator!
" << endl;

system("pause");
return 0;
}

I am getting the expected `(' before '{' token around line 75 and 76. I need help with this so that I can compile and run my program.

Line 75 starts at:

if{15 < Total_minutes <= 30){

Peter, in the line
if{15 < Total_minutes <= 30){
change
if{
to
if(

Also, syntax in the line
if(15 < total_minutes <= 30){
is incorrect. The line should read
if (15 < total_minutes && total_minutes <= 30) {

In my last answer to you, I talked about using fractional hours to calculate time difference, and that led to some floating point issues. Even though the code I gave you did work, I am having second thoughts and fractional hours is probably not the way to go because of the floating point issues. Sometimes my first impulse is not the best one. I agree with Ralph's post that minutes past midnight is a good representation for the starting and ending time. In my opinion, to make a truly robust program, you should still consider all the cases, such as when starting time is greater than ending time, and what that might mean. Such a case would indicate that the starting time was before midnight and the ending time was after midnight and the calculation for duration would be different from the case where starting time is less than ending time.

Again, for a tricky function like calculating time duration, it is good to write your test cases with expected results before writing the code.

I hope that helps.

Best regards
Zlatko

C++

Volunteer

#### Zlatko

##### Expertise

No longer taking questions.

##### Experience

No longer taking questions.

Education/Credentials
No longer taking questions.