samedi 26 septembre 2020

Why is my Else If 'vehicleHeight' code being ignored? [duplicate]

cout << "Are you driving a vehicle onto the ferry? (y/n) ";
    cin >> vehicle;
    if (vehicle == 'y' || vehicle == 'Y') {
        cout << "What is the length of the vehicle in feet? ";
        cin >> vehicleLength;
        if (vehicleLength > 20) {
            extraLengthCharge = (vehicleLength - 20) * extraLengthPrice; }
        cout << "Is the vehicle over 7 feet high? (y/n) ";
        cin >> vehicleHeight;
        if (vehicleHeight == 'y' || 'Y') {
            vehiclePrice = 69.00, fuelSurcharge = 10.40;
        } else if (vehicleHeight == 'n' || 'N') {
            vehiclePrice = 43.00, fuelSurcharge = 4.15;
        }
    else if (vehicle == 'n' || vehicle == 'N') {
        vehiclePrice = 0, fuelSurcharge = 0; }
    }

My code will give me the correct 'fare' if the response is yes, but if I type in no it will still assign the 'yes' value. I assume it has something to do with my else if statement format for vehicleHeight. Thanks and sorry for the novice question.

Aucun commentaire:

Enregistrer un commentaire