This assignment has me working with IF and ELSE statements and using them to validate certain ranges of variables and then to display an appropiate message if a variable is outside of a given range (i.e) "that number is not correct". I have written the program and compiled it. I'm trying to make the number zero invalid and able to be input in the program. However if you hit zero in the program it will display both the message for the invalid number and also the other message for any other variable that is entered and is valid.
Here is the source code. I've been beating my head trying to figure out how to make it just display the one message when zero is typed in. Well I gotta take a break and I'll be checking back in a while. Thanks for any help in advance.
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
float discount1 = .020; // amount of discount
float discount2 = .030;
float discount3 = .040;
float discount4 = .050;
float quantity; // # of packages
float totalCostOfPurchase; //final price
float price = 99; //price per package
cout << "Please enter the number of packages being sold. " <<endl;
cin >> quantity;
// determine discount based off of number of packages sold
if (quantity <= 0)
cout << "This amount is incorrect, please enter one or more to get the correct price and discount. " << endl;
if (quantity >= 1)
totalCostOfPurchase = price * quantity;
else if (quantity <= 9)
totalCostOfPurchase = price * quantity;
else if (quantity >= 10)
totalCostOfPurchase = price * quantity - discount1;
else if (quantity <= 19)
totalCostOfPurchase = price * quantity - discount1;
else if (quantity >= 20)
totalCostOfPurchase = price * quantity - discount2;
else if (quantity <= 49)
totalCostOfPurchase = price * quantity - discount2;
else if (quantity >= 50)
totalCostOfPurchase = price * quantity - discount3;
else if (quantity <= 99)
totalCostOfPurchase = price * quantity - discount3;
else if (quantity >= 100)
totalCostOfPurchase = price * quantity - discount4;
cout << "Thank you for your purchase. The final amount with your discount is $" <<totalCostOfPurchase <<endl;
return 0;
}