New to C++, Please help

I am having alot of difficulty with my program, and no clue to where to go from here to fix it. Everything I try brings more errors.




#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


// The following are constants for passengers traveling without vehicles.
const double adultFare = 13.00;
const double childFare = 6.50;

// The following are constants for passengers that are traveling with their vehicles.
const double passengerVehicle = 43.00;
const double oversizeVehicle = 69.00;
const double passengerSurcharge = 1.25;
const double vehicleSurcharge = 4.15;
const double oversizeSurcharge = 10.40;
const double passengerVehicleExtraFt = 2.15;
const double oversizeVehicleExtraFt = 3.45;
int main ()
{


cout << fixed << showpoint;
cout << setprecision(2);

int numOfAdults, numOfChild, overLength;
char reply, vehicle, overHeight;
double totalVehicle, totalSurcharge, totalFare;
cout << "Welcome to Kyle Cutler's Fare Calculator" << endl;


cout << "How many adults (age 12 or over) are in your party? ";
cin >> numOfAdults;
cout << "How many childre (age 5 to 11) are in your party? ";
cin >> numOfChild;
cout << "Are you driving a vehicle onto the ferry? (y/n): ";
cin >> vehicle;
switch (vehicle) {
// using a switch for the 2 possible choices: with or without cars
// using a switch for the 2 possible choices: two groups within length of vehicle????
case 'y':
case 'Y':

cout << "What is the length of the vehicle in feet? ";
cin >> overLength;

cout << "Is the vehicle over 7 feet high? (y/n): ";
cin >> overHeight;

if (overLength < 20)
{

if (overHeight == 'n')
totalVehicle = passengerVehicle + vehicleSurcharge;
totalSurcharge = ((numOfChild + numOfAdults) * passengerSurcharge) + vehicleSurcharge

else if ((overHeight == 'y')
totalVehicle = oversizeVehicle + oversizeSurcharge
totalSurcharge = ((numOfChild + numOfAdults) * passengerSurcharge) + oversizeSurcharge
}
else if ((overLength >= 20) && (overHeight == 'n'))
totalVehicle = passengerVehicle + passengerSurcharge + ((overLength - 20) * 2.15)
totalSurcharge = ((numOfChild + numOfAdults) * passengerSurcharge) + vehicleSurcharge


else if ((overLength >= 20) && (overHeight == 'y'))
totalVehicle = oversizeVehicle + passengerSurcharge + ((overLength - 20) * 3.45)
totalSurcharge = ((numOfChild + numOfAdults) * passengerSurcharge) + oversizeSurcharge

{

totalFare = totalVehicle + (numOfChild * childFare) + (numOfAdults * adultFare)
cout << "Your total fare is $ " << totalFare << "Your total surcharge is $ " << totalSurcharge << endl;
cout << "The total amount payable is $ " <<endl;
cout << "Thank you for using Kyle Cutler's Fare Calculator" << endl;
cout << "Press q or any other key followed by enter to quit: ";
cin >> reply;
return (0);
}
case 'n':
case 'N':






totalFare = (numOfChild * childFare) + (numOfAdults * adultFare)
cout << "Your total fare is $ " << totalFare << "Your total surcharge is $ " << endl;
cout << "The total amount payable is $ " <<endl;
cout << "Thank you for using Kyle Cutler's Fare Calculator" << endl;
cout << "Press q or any other key followed by enter to quit: ";
cin >> reply;
return (0);
}
Last edited on
Post the errors and use [ code ] [ /code ] , without the spaces shown, between your code to make it easier to read.
Last edited on
Error 10 error C2143: syntax error : missing ';' before '{' f:\bc2trysolution\bc2try\bc2.cpp 78
Error 5 error C2143: syntax error : missing ';' before '}' f:\bc2trysolution\bc2try\bc2.cpp 68
Error 1 error C2143: syntax error : missing ';' before 'else' f:\bc2trysolution\bc2try\bc2.cpp 65
Error 7 error C2143: syntax error : missing ';' before 'else' f:\bc2trysolution\bc2try\bc2.cpp 74
Error 3 error C2146: syntax error : missing ')' before identifier 'totalVehicle' f:\bc2trysolution\bc2try\bc2.cpp 66
Error 11 error C2146: syntax error : missing ';' before identifier 'cout' f:\bc2trysolution\bc2try\bc2.cpp 81
Error 12 error C2146: syntax error : missing ';' before identifier 'cout' f:\bc2trysolution\bc2try\bc2.cpp 97
Error 4 error C2146: syntax error : missing ';' before identifier 'totalSurcharge' f:\bc2trysolution\bc2try\bc2.cpp 67
Error 6 error C2146: syntax error : missing ';' before identifier 'totalSurcharge' f:\bc2trysolution\bc2try\bc2.cpp 71
Error 9 error C2146: syntax error : missing ';' before identifier 'totalSurcharge' f:\bc2trysolution\bc2try\bc2.cpp 76
Error 2 error C2181: illegal else without matching if f:\bc2trysolution\bc2try\bc2.cpp 65
Error 8 error C2181: illegal else without matching if f:\bc2trysolution\bc2try\bc2.cpp 74
Error 13 fatal error C1075: end of file found before the left brace '{' at 'f:\bc2trysolution\bc2try\bc2.cpp(28)' was matched f:\bc2trysolution\bc2try\bc2.cpp 104
These are simple syntax errors, no worry. Try posting your code inside the <> brackets so we can refer to the line numbers.

Basically, you are missing semicolons on the end of several statement and you need to keep in mind that any predicate (if, else if, while, for, etc) that has more than one statement after it needs brackets or else only the statement directly after it belongs to it.

1
2
3
4
5
6
7
8
9
10
if (x = 3)
   x = 4;    // belongs to the if statement
   y = 5;   // does not belong to the if statement unless you provide brackets


if (x = 3)
{
   x = 4;    // belongs to the if statement
   y = 5     // also belongs to the if statement because of the brackets
}
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
#include <iostream>	
#include <string>
#include <iomanip>
using namespace std;


// The following are constants for passengers traveling without vehicles.
const double adultFare = 13.00;
const double childFare = 6.50;

// The following are constants for passengers that are traveling with their vehicles.
const double passengerVehicle = 43.00;
const double oversizeVehicle = 69.00;
const double passengerSurcharge = 1.25;
const double vehicleSurcharge = 4.15;
const double oversizeSurcharge = 10.40;
const double passengerVehicleExtraFt = 2.15;
const double oversizeVehicleExtraFt = 3.45;
int main () 
{


cout << fixed << showpoint;
cout << setprecision(2);

int numOfAdults, numOfChild, overLength;
char reply, vehicle, overHeight;
double totalVehicle, totalSurcharge, totalFare; 
cout << "Welcome to Kyle Cutler's Fare Calculator" << endl;


cout << "How many adults (age 12 or over) are in your party? ";
cin >> numOfAdults;
cout << "How many childre (age 5 to 11) are in your party? ";
cin >> numOfChild;
cout << "Are you driving a vehicle onto the ferry? (y/n): ";
cin >> vehicle;
switch (vehicle) {
// using a switch for the 2 possible choices: with or without cars
// using a switch for the 2 possible choices: two groups within length of vehicle????
case 'y':
case 'Y':

cout << "What is the length of the vehicle in feet? ";
cin >> overLength;

cout << "Is the vehicle over 7 feet high? (y/n): ";
cin >> overHeight;

if (overLength < 20)
{

if (overHeight == 'n')
{totalVehicle = passengerVehicle + vehicleSurcharge;
totalSurcharge = ((numOfChild + numOfAdults) * passengerSurcharge) + vehicleSurcharge;
}
else if ((overHeight == 'y'))
{
totalVehicle = oversizeVehicle + oversizeSurcharge; 
totalSurcharge = ((numOfChild + numOfAdults) * passengerSurcharge) + oversizeSurcharge;
}
else if ((overLength >= 20) && (overHeight == 'n'))
{
totalVehicle = passengerVehicle + passengerSurcharge + ((overLength - 20) * 2.15);
totalSurcharge = ((numOfChild + numOfAdults) * passengerSurcharge) + vehicleSurcharge;
}

else if ((overLength >= 20) && (overHeight == 'y'))
{
totalVehicle = oversizeVehicle + passengerSurcharge + ((overLength - 20) * 3.45);
totalSurcharge = ((numOfChild + numOfAdults) * passengerSurcharge) + oversizeSurcharge;

totalFare = totalVehicle + (numOfChild * childFare) + (numOfAdults * adultFare); 
cout << "Your total fare is $ " << totalFare << "Your total surcharge is $ " << totalSurcharge << endl;
cout << "The total amount payable is $ " <<endl;
cout << "Thank you for using Kyle Cutler's Fare Calculator" << endl;
cout << "Press q or any other key followed by enter to quit: ";
cin >> reply;
return (0);

case 'n':
case 'N':


totalFare = (numOfChild * childFare) + (numOfAdults * adultFare) ;
cout << "Your total fare is $ " << totalFare << "Your total surcharge is $ " << endl;
cout << "The total amount payable is $ " <<endl;
cout << "Thank you for using Kyle Cutler's Fare Calculator" << endl;
cout << "Press q or any other key followed by enter to quit: ";
cin >> reply;
return (0);
}//end if 
}//end if
}//end of switch 


}/// end of main 




simple syntax errors no worries just remember your ";" and "{}" and you should be fine, the program seems unfinished make sure you check you code and write comments so we know what your doing ; cause so far i have no clue. ***the above code is The fix version for the syntax only, check your code along with this to see what you missed***
The "return (0)" on line 79 is kind of unnecessary though right?

Actually that whole structure is unnerving. The main function's return shouldn't be inside an if statement unless it is in an if else that determines whether the program succeeds or not. Even then you can always return a variable as your last return that smooths it out.

Barrington, since you were kind enough to quickly edit TS' code hopefully you might take the time to fully correct it.
Last edited on
It WOrks! Thank you for the suggestions!


Last edited on
I still dont know how to incorporate number line properly, please help.
There is a button on the right side of your text window that looks like <>. All it does in insert the tags [.code][./code] without the periods inside them. (I have to add the periods otherwise you can't see them.

Put you source code in between the tags.
Last edited on
Topic archived. No new replies allowed.