problems with repeating sentences..

This is a discussion on problems with repeating sentences.. within the C Programming forums, part of the General Programming Boards category; i am on the way of writing a program as my assignment.. it is about the total value of purchase ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    26

    problems with repeating sentences..

    i am on the way of writing a program as my assignment..

    it is about the total value of purchase after discount during a megasale.

    i encounter problem when writing it..

    the problem go as follw:

    10% discount is given to purchase>RM1000
    5% discount is given to purchase>500 and <1000
    2% discount is given to purchase>100 and<500
    no discount for purchase<= 100

    as when i debug and run it,

    it either appear all four sentences of " the total value of purchase is RMXXX"

    or the value is wrong...

    i am curious about the appearance all those four sentences simultaneously..

    and how come the value will wrong as i entered the correct formula: "total= a*(100-b)/100"

    please generously help me.. thank you..

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Show your code
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    26

    sorry.. i dont understand.. please have a look at it..

    i suppose code means the source code file...
    then i attached it already..
    Code:
    #include<stdio.h>
    int main ()
    
    {
    int a,b=0,total;
    
    
    printf("\nEnter the value of purchase: RM ");
    scanf("%d",&a);
    
    
     {
    if (a>1000)
    {b=10)
      }
    
    {
    if ((a>500) && (a<=1000))
     {b=5)
     }
    
      {
    if ((a>100) && (a<=500))
    (b=2)
      }
    
    
     {
    if (a<=100)
    (b=0);
     }
    
    {
    if (a<=0)
    printf("\nYou entered an invalid value."); }
    
    
    total= (a*(100-b)/100);
    
    printf("\nThe total value of purchase is RM %d.",total);
    
    return (0);
    
    }
    please have a look at it...
    thanks..

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    i suppose code means the source code file...
    Post the smallest and simplest compilable program that demonstrates the problem. The program you posted obviously does not complex due to elementary syntax errors.

    Also, kindly indent your code.
    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

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Also you are failing the indentation

    in your case the solution will be to use
    Code:
    if()
    {
    }
    else if()
    {
    }
    else if()
    {
    }
    else
    {
    }
    construction
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    Thanks for the help that you all have given me..

    although it was just a little help..
    and fortunately, i have successfully completed my program..
    thanks again and cheer..

  7. #7
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Oh, and for problems like this, you may want to look into using floats (or doubles if very large numbers are involved (it doesn't seem like that's the case here)) as fractional values with integers will almost always cause accuracy-related problems.
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 05:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. Help me for repeating decimal numbers plz
    By Supra in forum C Programming
    Replies: 3
    Last Post: 09-27-2001, 03:18 PM

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