I am trying to do a simple calculation. I just started C++ and learning about decisions. My program should calculate number of tickets and apply discount based on the number of tickets purchased. It will only execute one of the decisions.
int main()
{
double qty; // qty of tickets
double discount; // % of discount.
cout << "Special Group Pricing is available on 20+ tickets " <<endl << endl;
cout << "How many tickets to the LA Sparks game would you like? "; // # of tickets on same line.
cin >> qty;
cout << endl << endl << endl; // three spaces
qty *= 9.75; // qty times price.
discount = qty * .22, qty * .045; // configured the discount amount
cout << "Retail price for your tickets is $" << qty << endl << endl;
cout << "The discounted price for your tickets is $" << qty - discount<< endl << endl;
if (qty >= 20)
{
qty *= .22;
}
else
{
qty *= .045;
}
cout << "Your savings were $" << qty << endl << endl;
return 0;
}
You are to use an if / else statement to calculate the appropriate discount (Some of you may think of this as the amount saved).
The discount should be computed within the if / else statement.
We are trying to eliminate as much duplicate code as possible so the dollar amount should only be computed one time after the if / else statement used to compute the discount.
No cin or cout statements within the if / else blocks
//Get value from the user here
if(qty >= 20)
{
//Do all calculations to do with discounts here.
}
else
{
qty = qty * 0.22;
}
cout << "Price of your tickets is " << qty << "\n";
#include <iostream>
usingnamespace std;
int main()
{
double qty; // qty of tickets
float discount; // % of discount.
cout << "Special Group Pricing is available on 20+ tickets " <<endl << endl;
cout << "How many Tickets to the LA Sparks game would you like? "; // # of tickets on same line.
cin >> qty;
cout << endl << endl << endl; // three spaces
qty *= 9.75; // qty times price.
if (qty >= 20)
{
discount = qty * .22;
}
else
{
discount = qty * .045;
}
cout << "Retail price for your tickets is $" << qty << endl << endl;
cout << "The discounted price for your tickets is $" << qty - discount<< endl << endl;
cout << "Your savings were $" << discount << endl << endl;
return 0;
}