Compiler Error on return 0
Feb 25, 2015 at 1:44am UTC
When I compile my program in putty I get the following message: "railTicket.cpp:108:5: error: expected ‘(’ before ‘return’
return 0;
" ^
Here's my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
#include <iostream>
using namespace std;
int main()
{ //Begin main function
char destination, age;
float time, ticket_cost, amnt_paid, total_due;
int number_tickets, adultpeakB=10, adultpeakP=16, adultoffpeakB=8, adultoffpeakP=12;
cout << "Welcome to the Rail Road\n" ;
cout << "What is your destination? ([B]oston or [P]ittsburgh) " ;
cin >> destination;
cout << "What time will you travel? (Enter time between 0-2359) " ;
cin >> time;
cout << "What type of ticket are you buying? ([A]dult, [C]hild, or [S]enior " ;
cin >> age;
cout << "Each ticket will cost: $" ;
if (destination='B' )
{ if ((time>=700) && (time<=1800))
{ switch (age)
{ case 'A' :
cout << adultpeakB;
ticket_cost = adultpeakB;
break ;
case 'C' :
cout << adultpeakB*0.25;
ticket_cost = adultpeakB*0.25;
break ;
case 'S' :
cout << adultpeakB*0.5;
ticket_cost = adultpeakB*0.5;
break ;
}
}
else if ((time<700) || ((time>1800) && (time<=2359)))
{ switch (age)
{ case 'A' :
cout << adultoffpeakB;
ticket_cost = adultoffpeakB;
break ;
case 'C' :
cout << adultoffpeakB*0.25;
ticket_cost = adultoffpeakB*0.25;
break ;
case 'S' :
cout << adultoffpeakB*0.5;
ticket_cost = adultoffpeakB*0.5;
break ;
}
}
}
else if (destination='P' )
{ if ((time>=700) && (time<=1800))
{ switch (age)
{ case 'A' :
cout << adultpeakP;
ticket_cost = adultpeakP;
break ;
case 'C' :
cout << adultpeakP*0.25;
ticket_cost = adultpeakP*0.25;
break ;
case 'S' :
cout << adultpeakP*0.5;
ticket_cost = adultpeakP*0.5;
break ;
}
}
else if ((time<700) || ((time>1800) && (time<=2359)))
{ switch (age)
{ case 'A' :
cout << adultoffpeakP;
ticket_cost = adultoffpeakP;
break ;
case 'C' :
cout << adultoffpeakP*0.25;
ticket_cost = adultoffpeakP*0.25;
break ;
case 'S' :
cout << adultoffpeakP*0.5;
ticket_cost = adultoffpeakP*0.5;
break ;
}
}
}
cout << "How many tickets do you want? " ;
cin >> number_tickets;
if (number_tickets>0)
{ cout << "You owe $" << total_due << "\n" ;
}
else
{ cout << "Invalid Order \n" ;
}
cout << "How much will you pay?" ;
cin >> amnt_paid;
switch
return 0;
}
Last edited on Feb 25, 2015 at 1:48am UTC
Feb 25, 2015 at 1:59am UTC
Read what the error is telling you. You're having problem at the return 0.
there is a random "switch" right above return 0.
Whats it doing there?
Topic archived. No new replies allowed.