#include <iostream>
usingnamespace std;
int main ()
{
int quantity_shirts;
int price=12;
double discount;
double cost=quantity_shirts * price;
double total_cost=cost-(cost*discount);
double cost_shirt=total_cost/quantity_shirts;
cout <<"How many shirts would you like?\n"<<endl;
cin >> quantity_shirts;
if(quantity_shirts>=0)
{
if (quantity_shirts>=5 && quantity_shirts<=10)
discount=.10;
cout <<"The cost per shirt is"<<cost_shirt<< "and the total cost is $"<<total_cost<<endl;
if (quantity_shirts>=11 && quantity_shirts<=20)
discount=.15;
cout <<"The cost per shirt is"<<cost_shirt<< "and the total cost is $"<<total_cost<<endl;
if (quantity_shirts>=21 && quantity_shirts<=30)
discount=.20;
cout <<"The cost per shirt is"<<cost_shirt<< "and the total cost is $"<<total_cost<<endl;
if (quantity_shirts>=31)
discount=.10;
cout <<"The cost per shirt is"<<cost_shirt<< "and the total cost is $"<<total_cost<<endl;
}
else
cout << "Invalid Input: Please enter a nonnegative integer"<<endl;
system("PAUSE");
return 0;
}
You are calculating cost before asking the user to input quantity_shirts.
if (quantity_shirts>=11 && quantity_shirts<=20)
{
discount=.15;
total_cost=cost-(cost*discount); //now we can calculate it because discount has a value
}
//.. other if's
//below only needs to be done once, it's the values of the variables that need to be changed in the if's
cout <<"The cost per shirt is"<<cost_shirt<< "and the total cost is $"<<total_cost<<endl;
You have the same issue with double cost_shirt=total_cost/quantity_shirts; - quantity_shirts has no value at that moment.
No just do this..
cout <<"How many shirts would you like?\n"<<endl;
cin >> quantity_shirts;
int quantity_shirts;
int price=12;
double discount;
double cost=quantity_shirts * price;
double total_cost=cost-(cost*discount);
double cost_shirt=total_cost/quantity_shirts;