if else loop

keeps failing and i don't know why. can some one please help me?

//Write a C++ program to get the input of number of tickets for an amusement
//park. Each ticket costs $ 5.50.
//Every fifth ticket is free.
//If any person is less than 5 or greater than 65 (by age), then they get a
//discount of 1.08.
//Calculate the total price for group of visitors.
//Specification: You can either use do-while / while / if-else if / switch

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

int numOfTickets = 0;
int ticketCost = 0;
int individualTicket = 0;
int age = 0;
int discount = 0;
int numOfGroup = 0;
int totalPrice = 0;
int i = 0;
int numOfDiscounts = 0;
int discount2 = 0;



cout << "How many tickets do you need?" << endl;
cin >> numOfTickets << endl;

cout << " How many are over 65 or under 5?" << endl;
cin >> numOfDiscounts << endl;

discount = numOfDiscounts * 1.08;

if (numOfTickets < 5){
discount2 = 0;
}
if else (numOfTickets > 4 && numOfTickets < 10){
discount2 = 5.50;
}
if else (numOfTickets > 10 && numOfTickets < 15){
discount2 = (5.50 * 2);
}
if else (numOfTickets > 15 && numOfTickets < 20){
discount2 = (5.50 * 3);
}
if else (numOfTickets > 20 && numOfTickets < 25){
discount2 = (5.50 * 4);
}
if else (numOfTickets > 25 && (numOfTickets < 30){
discount2 = (5.50 * 5);
}

totalPrice = (numOfTickets * 5.50) - discount - discount2;
cout << "Your total price is $" << totalPrice << endl;






}

}
Last edited on
Where is your main function?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
if (numOfTickets < 5){
discount2 = 0;
}
if else (numOfTickets > 4 && numOfTickets < 10){
discount2 = 5.50;
}
if else (numOfTickets > 10 && numOfTickets < 15){
discount2 = (5.50 * 2);
}
if else (numOfTickets > 15 && numOfTickets < 20){
discount2 = (5.50 * 3);
}
if else (numOfTickets > 20 && numOfTickets < 25){
discount2 = (5.50 * 4);
}
if else (numOfTickets > 25 && (numOfTickets < 30){
discount2 = (5.50 * 5);
}


Should be :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
if (numOfTickets < 5){
discount2 = 0;
}
else if (numOfTickets > 4 && numOfTickets < 10){
discount2 = 5.50;
}
else if (numOfTickets > 10 && numOfTickets < 15){
discount2 = (5.50 * 2);
}
else if (numOfTickets > 15 && numOfTickets < 20){
discount2 = (5.50 * 3);
}
else if (numOfTickets > 20 && numOfTickets < 25){
discount2 = (5.50 * 4);
}
else if (numOfTickets > 25 && (numOfTickets < 30){
discount2 = (5.50 * 5);
}

Topic archived. No new replies allowed.