Hi, I am a beginner in coding altogether, and the if else statement is really confusing me.?
My assignment is to
Prompt the user to determine if they have a discount coupon ("Y" for yes, anything else for no)
If the user has a discount coupon, determine if it's for a free adult ticket or for a free childrens ticket ("A" for adult, "C" for child, anything else is an error)
using the if else statement. I am not looking for the code, I just need to know what the order of the else if statement would so I can understand what it would look like.
This is uncompleted code below, I just added it to give you a point of where I am. This could wrong below
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double adult, child;
int priceAdult, priceChild, total;
string couponType, discount;
//get the number of adult tickets they would like to purchase
cout << "Enter the amount of adult tickets that are being purchased: ";
cin >> adult;
//get the number of child tickets they would like to purchase
cout << "Enter the amount of child tickets that are being purchased: ";
cin >> child;
//If the user has a coupon
// Ask for a discount coupon
cout << "Do you have a discount coupon? (Y for yes, anything else for no): ";
cin >> couponType;
if ( couponType == "Y" )
{
//ask whether it is for adult or child
cout << "Is this coupon for an adult or child ticket?(A for adult, C for Child): ";
if ( discount == "A" )
{
total = priceAdult - 10.50;
cout << "Discount: " << priceAdult << endl;
}
else ( discount == "C" );
{
total = adult * 10.50 ;
}
}
else
{
total = priceAdult + priceChild;
}
cout << endl;
return 0;
}
here's another few things:
1)what is the value of priceAdult?
2)what does the magic number 10.50 stand for?
3)why do you subtract it from garbage to get total and then multiply adult (more garbage) with it to get the same total.
4)what happens if the user enters 'y' for couponType.
5)post the corrected code AND errors and someone is sure to help you especially if you enclose the code in code tags (< > )