Thread: Need help with my school assignment

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    4

    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 units bought :10
    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

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Discount1 and Discount2 are not int's, but you declared them as int's.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    4
    Quote Originally Posted by DaveH View Post
    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?
    Last edited by Shazarul; 11-16-2011 at 08:13 AM. Reason: To thank the person above me

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    You can define them as floats. It just depends on the size of number you expect to fill it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help on this school assignment on for loop
    By spyropyro in forum C Programming
    Replies: 1
    Last Post: 12-01-2010, 02:07 AM
  2. C++ code for school assignment
    By Pupo in forum C++ Programming
    Replies: 3
    Last Post: 03-09-2010, 08:11 AM
  3. Help for school assignment
    By Allynia in forum C Programming
    Replies: 9
    Last Post: 04-29-2008, 03:07 PM
  4. School assignment...NEED HELP
    By godfrey270487 in forum C++ Programming
    Replies: 12
    Last Post: 03-09-2006, 02:35 PM
  5. stupid school assignment
    By major_small in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 11-20-2003, 10:06 AM