Thread: Problem

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    16

    Problem

    It doesn't display the cost correctly. It just calculates the total x without taking into account the discount. What would I have to change/add to get the total cost after it calculates the discount?

    double cost;
    double total_cost;
    double value;
    int x;
    float discount;

    cout<<"Enter the number of units sold: ";
    cin>> x;

    cost=(quantity * 99);

    cost=(x * 50);
    if (x < 10)
    discount=(0.0);
    else if (x < 20)
    discount=(0.2);
    else if ( x < 40 )
    discount=(0.3);
    else if (x < 50)
    discount=(0.4);
    else
    discount=(0.5);

    value=(cost*discount);
    total_cost= (cost - value);

    cout<<"Total cost " << total_cost;

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This is in the process of being answered elsewhere.

    By the way, you should use topic titles that are more descriptive than "Problem".
    Last edited by laserlight; 08-31-2009 at 05:50 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    16
    Seems I can't change the title now.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Code:
    double cost;
    double total_cost;
    double value;
    int x;
    float discount;
    
    cout<<"Enter the number of units sold: ";
    cin>> x;
    
    cost=(quantity * 99);
    
    cost=(x * 50);
    if (x < 10)
    discount=(0.0);
    else if (x < 20)
    discount=(0.2);
    else if ( x < 40 )
    discount=(0.3);
    else if (x < 50)
    discount=(0.4);
    else
    discount=(0.5);
    
    value=(cost*discount);
    total_cost= (cost - value);
    
    cout<<"Total cost " << total_cost;
    Saved for posterity.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM