program for finding gross salary

• 12-04-2008
newbcore
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.
• 12-04-2008
tabstop
And do you expect the compiler to reorder your code? How can you compute gross_salary before you ask for the basic salary?
• 12-04-2008
jwenting
Or maybe the program is just very smart and knows Ramesh doesn't deserve to get paid ;)
• 12-05-2008
QuantumPete
Quote:

Originally Posted by tabstop
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
• 12-05-2008
matsp
Quote:

Originally Posted by QuantumPete
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
• 12-05-2008
newbcore
Quote:

Originally Posted by tabstop
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.
• 12-05-2008
Matus
Quote:

Originally Posted by newbcore
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?
• 12-05-2008
newbcore
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!