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;
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);
}
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
}
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
// The following are constants for passengers traveling without vehicles.
constdouble adultFare = 13.00;
constdouble childFare = 6.50;
// The following are constants for passengers that are traveling with their vehicles.
constdouble passengerVehicle = 43.00;
constdouble oversizeVehicle = 69.00;
constdouble passengerSurcharge = 1.25;
constdouble vehicleSurcharge = 4.15;
constdouble oversizeSurcharge = 10.40;
constdouble passengerVehicleExtraFt = 2.15;
constdouble 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;
}
elseif ((overHeight == 'y'))
{
totalVehicle = oversizeVehicle + oversizeSurcharge;
totalSurcharge = ((numOfChild + numOfAdults) * passengerSurcharge) + oversizeSurcharge;
}
elseif ((overLength >= 20) && (overHeight == 'n'))
{
totalVehicle = passengerVehicle + passengerSurcharge + ((overLength - 20) * 2.15);
totalSurcharge = ((numOfChild + numOfAdults) * passengerSurcharge) + vehicleSurcharge;
}
elseif ((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.
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.