# Need help with my school assignment

• 11-16-2011
Shazarul
Need help with my school assignment
Hi guys I've been trying a lot of times, even seek help from some of my buddies but they themselves are having a the same problem. Just a simple C++ thanks in advance and using Microsoft Visual Studios 2010

This is what I should get after I build the program;

[tag]"Please enter units bought : 10
Please enter unit price : \$15.50

Total cost (Before the discount) = \$155.00
The discount = \$25.42
The total discounted cost = \$129.58
Press any key to continue . . . "

But when i build my code it only appear as

Please enter unit price : \$15.50

Total cost (before the discount) = \$155.00
The discount =\$0.00
The total discounted cost = \$155.00
Press any key to continue . . ."

The error is in Purple font and below is my question.
[\tag]
"A wholsesale company offers a double discounts of each of its products depending on the number of units bought and the price per unit. These discounts are given in the following tables:

Number Bought Discount1 (On total cost)
1--9 5%
10--19 12%
20--49 20%
50 or more 32%

Unit Price Discount2 (On unit price)
\$20.00 or below 5%
Above \$20.00 20%

Write a program that will read in the number bought and the unit price and then calculate and print the total cost (before the discount), the total discounted cost and the discount, where
. Total cost (before Discount) = Number Bought * Unit Price
. Discounted Price = Unit Price * (1 - Discount2)
. Total Discounted Cost = Number Bought * Discounted Price * (1 - Discount1)
. Discount = Total Cost (Before Discount) - Total Discounted Cost

Here is my code

Code:

```#include <iostream> #include <iomanip> using namespace std; int main() {     int uBought, Discount1, Discount2;     double uPrice, tCost, dPrice, Discount, tDcost;     cout << "Please enter units bought :";     cin >> uBought;     if ( uBought >= 50)         Discount1 = 0.32;         else if ( uBought >= 20)             Discount1 = 0.20;         else if ( uBought >= 10)             Discount1 = 0.12;         else             Discount1 = 0.05;         cout << "Please enter unit price : \$";     cin >> uPrice;     if ( uPrice > 20)         Discount2 = 0.20;         else             Discount2 = 0.05;     tCost = uBought * uPrice;     dPrice = uPrice * (1-Discount2);     tDcost = uBought * dPrice * (1-Discount1);     Discount = tCost - tDcost;     cout << setprecision (2) << fixed << "\n\nTotal cost (before the discount) = \$" << tCost;     cout << "\nThe discount = \$" << Discount;     cout << "\nThe total discounted cost = \$" << tDcost << endl;     system("pause");     return 0; }```
I have a feeling its my declaration? No idea help would be appreciated thanks :)
• 11-16-2011
DaveH
Discount1 and Discount2 are not int's, but you declared them as int's.
• 11-16-2011
Shazarul
Quote:

Originally Posted by DaveH
Discount1 and Discount2 are not int's, but you declared them as int's.

OUH! HAHA Sec let me try it out!

*Wooot! Thanks my gawd that was soo simple and yet I . . Blargh! I think I'am sleepy, thanks dude . .
Declared them as double . . Side question can i declare them as float as well?
• 11-16-2011
DaveH
You can define them as floats. It just depends on the size of number you expect to fill it.