I'm writing a program from my C++ class. Its called Software Sales. It wants me to write a program for a software company that sells a package that retails at $99. The quantity discounts are:
if you buy 10-19, 20% off
if you buy 20-49, 30% off
if you buy 50-99, 40% off
if you buy 100 or more, 50% off
If the user puts 0 or less for the quantity, I have to display that they can't enter a 0 or less for the quantity and the program must end.
I am using if, else if, statements. My error is in the first if statement:
if (quantity >= 0)
cout << "Invaild number." << return 0;
The word return is underlined in red and says expected a expression. What am I doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Declare variables
int quantity;
double discount = 0.0, regprice = 0.0, total = 0.0;
// Asks for user input
cout << "Enter the number of software packages sold: ";
cin >> quantity;
// Calculates regular price
regprice = 99 * quantity;
// Calcualtes discount
if (quantity >= 0)
cout << "Invaild number." << return 0;
else if (quantity < 10)
discount = regprice * 0;
else if (quantity < 20)
discount = regprice * 0.20;
else if (quantity < 50)
discount = regprice * 0.30;
else if (quantity < 100)
discount = regprice * 0.40;
else if (quantity >= 100)
discount = regprice * 0.50;
total = (99 * quantity) - discount;
// Displays results
cout << "Price without discout: $" << regprice << endl;
cout << "Discount amount: $" << discount << endl;
cout << "Your price: $" << total << endl;
return 0;
}
|