Problem

This is a discussion on Problem within the C++ Programming forums, part of the General Programming Boards category; It doesn't display the cost correctly. It just calculates the total x without taking into account the discount. What would ...

  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
    21,409
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,424
    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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21