Hello! I'm just starting to learn C++, so I'm not quite sure what I'm doing yet.
For this program, I have to write a program that will calculate how much a person pays to go to the zoo. The user inputs the cost of admission and age. If the person is under 5, it's free. If they're ages 5-12, it's half-off. If between 13 and 59, it's full price. If they're above 60, it's a 30% discount. The program also needs to ask the user if they want a hotdog and/or a soft drink, then add 7% sales tax to the food (I havent gotten to the tax part yet).
My main question right now is how to put all the cout statements at the bottom, so they all output together after everything else (kind of like a receipt). I'm just not sure how to do it because of the if statements (which I am using for the first time). How do I put all the cout statements at the end and still make it only output one cout, depending on their age?
Also if you have any other suggestions of how to improve my program, I would appreciate it!
Thanks in advance!
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
double admissionPrice;//the price of admission
int age;//the age of the user
cout << "What is the price of admission? (excluding a dollar sign):" << endl;
cin >> admissionPrice;
cout << "What is the age of the person going to the zoo?" << endl;
cin >> age;
double freeAdmission;//the admission price for a child under 5
double halfPriceAdmission;//the admission price for children ages 5-12
double thirtyPercentDiscount;//the admission price for people over 60
freeAdmission = admissionPrice * 0;
halfPriceAdmission = admissionPrice / 2;
thirtyPercentDiscount = admissionPrice - (admissionPrice * .3);
if (age < 5)
{
cout << "Free Admission: $" << fixed << showpoint << setprecision(2) << freeAdmission << endl;
}
elseif (5 <= age && age <= 12)
{
cout << "Half Price Admission: $" << fixed << showpoint << setprecision(2) << halfPriceAdmission << endl;
}
elseif (13 <= age && age <= 59)
{
cout << "Admission Price: $" << fixed << showpoint << setprecision(2) << admissionPrice << endl;
}
elseif (age >= 60)
{
cout << "30% Discount: $" << fixed << showpoint << setprecision(2) << thirtyPercentDiscount << endl;
}
double hotdogPrice;//the price of a hot dog
char h;//their answer to the question if they want a hot dog
char Y; char y;//yes
char N; char n;//no
hotdogPrice = 2.50;
cout << "Do you want a hot dog? Y for yes, N for no." << endl;
cin >> h;
if(h == 'Y' || h == 'y')
{
cout << "Hot dog: $" << fixed << showpoint << setprecision(2) << hotdogPrice <<endl;
}
elseif(h == 'N' || h == 'n')
{
cout << "No hotdog" << endl;
}
char d;//their answer to the question if they want a soft drink
char s;//their answer to what size soft drink they want
char M; char m;//medium soft drink
char L; char l;//large soft drink
double mediumPrice;//price of a medium soft drink
double largePrice;//price of a large soft drink
mediumPrice = 2.50;
largePrice = 4.00;
cout << "Do you want a soft drink? Y for yes, N for no." << endl;
cin >> d;
if (d == 'Y' || d == 'y')
{
cout << "Do you want a medium or large soft drink? M for medium, L for large" << endl;
cin >> s;
if (s == 'M' || s == 'm')
cout << "Medium drink: $" << mediumPrice << endl;
elseif (s == 'L' || s == 'l')
cout << "Large soft drink: $" << largePrice << endl;
}
elseif (d == 'N' || d == 'n')
cout << "No soft drink" << endl;
system("pause");
return 0;
}