expected primary expression before else

hi, i keep getting an 'expected primary expression before else' error. not quite sure where the problem is.

i'm a beginning computer science and c++ student.

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
#include <iostream>  
#include <iomanip>               
#include <string>                   

using namespace std;               

int main ()
{
    int adults;
    int children;
    int vehicleLength;
    double adultFareTotal;
    double childFareTotal;
    double vehicleCost;
    double fuelSurcharge;
    double totalFare;
    double overallTotal;
    char vehicle;
    char vehicleHeightLimit;
    
    cout << fixed;
    cout << setprecision(2);
    
    cout << "Welcome to Robert Williams' Fare Calculator" << endl;
    cout << "How many adults (age 12 or over) are in your party? ";
    cin >> adults;
    cout << "How many children (age 5 to 11) are in your party? ";
    cin >> children;
    cout << "Are you driving a vehicle onto the ferry? ";
    cin >> vehicle; 
    
    totalFare = adults * 13.00 + children * 6.50;
    
    if (vehicle == 'y');
        cout << "What is the length of the vehicle in feet? ";
        cin >> vehicleLength;
        vehicleCost = 43.00 + (vehicleLength - 20) * 2.15;
        fuelSurcharge = 4.15 + (adults + children) * 1.25;
        overallTotal = totalFare + fuelSurcharge + vehicleCost;
    
        cout << "Is the vehicle over 7 feet high? ";
        cin >> vehicleHeightLimit;
    
        if (vehicleHeightLimit == 'y');
           vehicleCost = 69.00 + (vehicleLength - 20) * 3.45;
           fuelSurcharge = 10.40 + (adults + children) * 1.25;
           overallTotal = totalFare + fuelSurcharge + vehicleCost;
         
    else if (vehicle == 'n');
        fuelSurcharge = (adults + children) * 1.25;
        overallTotal = totalFare + fuelSurcharge;
          
           
    cout << "Your fare is " << totalFare << " plus a fuel surcharge of " << fuelSurcharge << endl;
    cout << "The total amount payable is " << overallTotal << endl;
          
      
    
    //This section stops the program 'flashing' off the screen.
    char reply;
    cout << "Press q (or any other key) followed by 'Enter' to quit: ";
    cin >> reply;
    return 0;
}
Errors begin on line 34. Look up how the conditional operators work and what exactly the ; means in C++.
Your code reminds me of python :)

In C/C++ you need to wrap statements with { } if you want them to execute together.

as sasauke says, your error begins at line 34. I recommend reading about statements and flow control here. Compare the example if statements with your own.
http://www.cplusplus.com/doc/tutorial/control/
Topic archived. No new replies allowed.