do while loop is not working

I need the program to re-run when Y is inputted for choice.

#include <iostream>
using namespace std;
int main()
{
int numberTransfers;
char choice = 'Y, N';
char ticketClass = 'E, O, F, X';
char calculate = '1, 2, 3, 4';
double cost, baseCost, totalCost, numberMiles, subcharge;
do {
cout << "Enter ticket class =>" <<endl;
cin >> ticketClass;

if ((ticketClass != 'E' && ticketClass != 'F' && ticketClass != 'O' && ticketClass != 'X'))
{
cout << "Invalid input!";


return 0;
}
else
{



cout << "Enter number of miles traveled =>"<<endl;
cin >> numberMiles;
cout << "Enter number of tranfers =>"<<endl;
cin >> numberTransfers;


cost = numberMiles*.10;
baseCost = cost-(50*numberTransfers);
subcharge = (baseCost * calculate);







cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << "The base fare is $" << cost <<endl;
cout << "With " <<numberTransfers<< " transfers, the base cost is $" << baseCost <<endl;
cout << "Enter 1 for E ticket class"<<endl;
cout << "Enter 2 for F ticket class"<<endl;
cout << "Enter 3 for O ticket class"<<endl;
cout << "Enter 4 for X ticket class"<<endl;
cin >> calculate;

switch (calculate)
{
case '1':
subcharge = (baseCost *1);
break;
case '2':
subcharge = (baseCost *2.5);
case '3' :
subcharge = (baseCost *5);
case '4' :
subcharge = (baseCost *3);
}
cout << "Your subcharge is $"<< subcharge <<endl;

totalCost = subcharge +(subcharge*.10);

cout << "With a 10% sales tax the total cost is $" <<totalCost <<endl;
cout << "Run the program again? Y or N" << endl;
cin >> choice;
if (choice != 'N' && choice != 'Y')
{
cout << "Invalid input";
}

return 0;
}

} while (choice == 'Y'); }
There is a return 0; before execution gets to the end of the do-while loop.

Incidentally, these lines don't make much sense - but your compiler should have already told you that:
1
2
3
    char choice = 'Y, N';
    char ticketClass = 'E, O, F, X';
    char calculate = '1, 2, 3, 4';
Last edited on
Topic archived. No new replies allowed.