Thread: error in program

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

    Unhappy error in program

    Hello,
    I m very new to c program , and is unable to solve the simple program. please help me.

    to input basic salary and to find gross salary if dearness allowance is 40% of basic salary and house rent allowance is 20% of basic salary
    Code:
    #include <stdio.h>
    #include <math.h>
    
    
    int main()
    {
        int bs,da,hra,gs;
        printf("basic salary :");
        scanf("%d\n",&bs);
        da=40/100*bs;
        hra=20/100*bs;
        gs=bs+da+hra;
        printf(" The gross salary is :%d\n",gs );
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    What are you having problems with?

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    14
    basic salary displays and I put any number, but it does not calculate the gross salary.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > da=40/100*bs;
    > hra=20/100*bs;
    Compare with say ( bs * 40 ) / 100
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    14
    @salem ,, no its same , the gross salary doesnt show up

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547

    fized math

    Referring to message 1...

    Remove the \n from line 9 ....
    line 10 should be da = (bs * 40) / 100;
    line 11 should be hra = (bs * 20) / 100;
    Last edited by CommonTater; 11-03-2011 at 07:00 AM.

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    14
    thank you common tater, line 9 was creating problem, now its working fine

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by psaikia View Post
    thank you common tater, line 9 was creating problem, now its working fine
    You're welcome... Just don't be putting \n in scanf() format strings in future

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 11-03-2010, 12:45 PM
  2. C Program... Program or Compiler error?
    By Zemira in forum C Programming
    Replies: 13
    Last Post: 12-02-2009, 08:59 PM
  3. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  4. i'm trying to fix an error with my error messaging on my program
    By RancidWannaRiot in forum C++ Programming
    Replies: 10
    Last Post: 09-30-2003, 01:02 PM
  5. one error in the program...
    By davidvoyage200 in forum C++ Programming
    Replies: 6
    Last Post: 01-31-2003, 08:28 PM