Thread: program for finding gross salary

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    25

    program for finding gross salary

    Greetings earthlings,

    Ok, so I'm trying to write this program in which the user enters in a person's basic salary, and the program calculates the gross salary. Gross salary is the basic salary plus something called a dearness allowance (which is 40% of the basic salary) plus the house rent (which is 20% of the basic salary).

    I can enter in the basic salary, but then it will say Ramesh's gross salary is 0.00 rupees. What is the reason it does that? I also don't know what's going on with the getchar() thing. I don't even know what that is. I just know that if I don't put it in, the screen will only pop up for a second and then close.


    Code:
    #include <stdio.h>
    main()
    {
          float basic_salary, gross_salary, dearness_allowance = .4, house_rent = .2;
          gross_salary = (basic_salary+basic_salary*dearness_allowance)+(basic_salary*house_rent);
          
          printf("Please enter Ramesh's basic salary.\n");
          scanf("%f", &basic_salary);
          getchar();
          printf("Ramesh's gross salary is %.2f rupees.\n", gross_salary);
          getchar();
          }
    As always, thanks y'all.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    And do you expect the compiler to reorder your code? How can you compute gross_salary before you ask for the basic salary?

  3. #3
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    Or maybe the program is just very smart and knows Ramesh doesn't deserve to get paid

  4. #4
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by tabstop View Post
    And do you expect the compiler to reorder your code? How can you compute gross_salary before you ask for the basic salary?
    There are languages (the obscure type used only at universities), where you can declare an identity, then set one of the variables in it and the result will automatically change. Your code would look exactly like the OP's.
    EDEN developed at the University of Warwick is one of those languages.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by QuantumPete View Post
    There are languages (the obscure type used only at universities), where you can declare an identity, then set one of the variables in it and the result will automatically change. Your code would look exactly like the OP's.
    EDEN developed at the University of Warwick is one of those languages.

    QuantumPete
    However, C or C++ is NOT one of those languages.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    25
    Quote Originally Posted by tabstop View Post
    And do you expect the compiler to reorder your code? How can you compute gross_salary before you ask for the basic salary?
    why yes, yes i do . . . and to give me a cookie too.

    in any event, thanks, and the problem is solved.

  7. #7
    POeT GuY Matus's Avatar
    Join Date
    Feb 2008
    Location
    Bz
    Posts
    235
    Quote Originally Posted by newbcore View Post
    why yes, yes i do . . . and to give me a cookie too.

    in any event, thanks, and the problem is solved.
    You gota be nicer to the people here see, don't expect a cookie i thought so first, but always give it a good try first, so is the problem solved?
    PoEms R InsPiRatiOns of LIfE ExpErienCes!!


  8. #8
    Registered User
    Join Date
    Nov 2008
    Posts
    25

    Cool

    I was kidding in response to the "And do you expect the compiler to reorder your code?" comment . Remember, I'm wet behind the ears and just learning that there's an order I'm supposed to follow!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. Salary Range Calculator help please!! =(
    By bambino in forum C++ Programming
    Replies: 3
    Last Post: 04-20-2006, 06:17 PM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. Help with sample tax program
    By DaMonsta in forum C Programming
    Replies: 1
    Last Post: 05-15-2003, 03:45 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM