Thread: Code is right. Execution is wrong! HELP

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    28

    Code is right. Execution is wrong! HELP

    Hello everyone,

    This program is used to calculate the discount on a given number given its discount rate.

    Code:
    #include <stdio.h>
    
    int main ()
    
    {
        int n, percent, intresult = 0 , result = 0 ;
    
        printf ("Enter the number\n\n") ;
    
        scanf ("%i", &n) ;
    
        printf ("\n\nLess %% ?\n\n") ;
    
        scanf ("%i", &percent) ;
    
        intresult = (percent / 100) * n ;
    
        result = n - intresult ;
    
        printf ("\n\nTotal = %i\n\n", result) ;
    
        getchar () ;
    
        return 0 ;
    
    }
    The result that am getting is the number typed in by the user itself.
    There is no calculation happening on the number.

    Please help

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Lookup up integer division in C.

    4/3 equals 1
    4/3.0 equals 1.33333

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    28
    Thx man. I missed an easy one

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 02-28-2012, 02:12 AM
  2. Arbitrary Code Execution on the Zune?
    By User Name: in forum C# Programming
    Replies: 0
    Last Post: 06-10-2010, 08:13 PM
  3. order of execution of tokens in a c++ source code
    By sandy.sandipanc in forum C++ Programming
    Replies: 4
    Last Post: 10-04-2008, 12:34 PM
  4. Arbitrary Code Execution
    By CrazyNorman in forum C++ Programming
    Replies: 3
    Last Post: 04-10-2007, 02:33 PM