I am working on the following practice project for C++, VS 2010 -
Write code for the following
A software company sells a package that retails for $99. Quantity discounts
are given according to the following table -
Quantity Discount
10-19 20%
20-49 30%
50-99 40%
100 or more 50%
Write a program that asks the user to enter the number of packages purchased.
The program should then display the amount of the discount (if any) and the
total amount of the purchase after the discount.
This will run with errors
Errors -
(25): error C2065: 'discount' : undeclared identifier
(26): error C2065: 'total' : undeclared identifier
(35): error C2065: 'discount' : undeclared identifier
(37): error C2065: 'discount' : undeclared identifier
(39): error C2065: 'discount' : undeclared identifier
(41): error C2065: 'discount' : undeclared identifier
(43): error C2065: 'discount' : undeclared identifier
(47): error C2065: 'discount' : undeclared identifier
(52): error C2065: 'total' : undeclared identifier
(52): error C2065: 'discount' : undeclared identifier
(55): error C2065: 'total' : undeclared identifier
I declared discount as zero, then did the calculations to reset for each run. It will output the discount, but will not run the total correctly.
What am I missing?
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 41 42 43 44 45 46 47
|
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
//set variables
double quantity = 0;
discount = 0;
total = 0;
// require user input
cout << "Enter the quantity for your purchase: ";
cin >> quantity;
// determine discount
if (quantity <= 19)
discount = .2;
else if (quantity >= 20 && quantity <= 79)
discount = .3;
else if ( quantity > 79 && quantity <= 99)
discount = .4;
else if ( quantity > 100)
discount = .5;
else if (quantity < 10)
discount = 0;
// show discount percentage
cout << "Your discount on this purchase is " << discount << '.' << endl;
//declare constant & calculate
double item = 99;
total = quantity * item - discount;
//output total purchase
cout << "Your total price is " << total << '.' << endl;
return 0;
}
|