#include <iostream>
#include <iomanip>
usingnamespace std;
//for single customers
constdouble single_first_30_minutes = 7.00;
constdouble single_after_30_minutes = 1.50;
//for couple customers
constdouble couple_first_30_minutes = 10.50;
constdouble couple_after_30_minutes = 2.50;
//for group customers
constdouble group_first_30_minutes = 16.00;
constdouble group_after_30_minutes = 4.00;
//To figure out if time is less then or equal to 30 minutes
constdouble mintime = 30;
constdouble mintimetwo = 20;
constdouble mintimethree = 15;
//To figure out if customer needs to pay an additional $50 fee
constdouble maxtime = 60;
int main()
{
char travelerType;
int time;
double total;
cout << fixed << showpoint;
cout << setprecision(2);
cout << "This program will calculate your ticket."<<endl<<endl;
cout << "Please enter passenger type: S or s (single), "
<< "C or c (couple), "
<< "G or g (group). "<<endl;
cin >> travelerType;
cout << endl;
while (travelerType!='stop')
{
if (travelerType=='S' || travelerType=='s')
{
cout << "Please type in your travel time, or type 'stop' to exit: ";
cin >> time;
cout << endl;
if (time <= mintime)
{
cout << "Your total is: $7.00" << endl;
}
elseif (time > mintime)
{
total = single_first_30_minutes + (single_after_30_minutes * time);
cout << "Your total is: $" << total << endl;
}
} //closes first if statement
if (travelerType=='C' || travelerType=='c')
{
cout << "Please type in your travel time, or type 'stop' to exit: ";
cin >> time;
cout << endl;
if (time < mintime)
{
cout << "Your total is: $10.50" << endl;
}
elseif (time > mintimetwo)
{
total = couple_first_30_minutes + (couple_after_30_minutes * time);
cout << "Your total is: $" << total << endl;
cout << endl;
}
} //closes second if statement
if (travelerType=='G' || travelerType=='g')
{
cout << "Please type in your travel time, or type 'stop' to exit: ";
cin >> time;
cout << endl;
if (time < mintimethree)
{
cout << "Your total is: $16.00" << endl;
}
elseif (time > mintimethree && time > 30)
{
total = group_first_30_minutes + (group_after_30_minutes * time) + 50;
cout << "Your total is: $"<< total << endl;
cout << endl;
}
elseif (time > mintimethree)
{
total=group_first_30_minutes+(group_after_30_minutes * time);
cout << "Your total is: $" << total << endl;
cout << endl;
}
} //closes third if statement
elseif (travelerType=='stop');
else
cout << "Your input is invalid, please try again.";
} //End While loop
cout << "Stop has been entered; program exited. Thanks for using the fare calculator!"<<endl;
system ("pause");
return 0;
}
I'm not going to lie, this is school work but it is about 90% done, there are some problems I cannot find in the program such as the else statement executing reguardless of the if statements being true, and an infinite while loop when the breaking word 'stop' is entered. I completely understand if you cannot help, but I would appreciate any help given and will +rep everyone who helps. I'm not a complete novice programmer, but I've been pulling my hair out for 2 days now and cannot for the life of me find the mistake...
The while loop: I see that travelerType is a char, which means it holds one character. So it can't ever hold "stop", a string. You also cannot put a string inside single quotes like you have there; single quotes are for "single character constants" only, not strings. String literals use double quotes.
I have to say, though, your indentation could use some work. Indent everything in a block; that might help you see better which else's connect to which if's, I imagine that is the problem with your else statement.