# Thread: Arithmetic not calculating, though program runs

1. ## Arithmetic not calculating, though program runs

Hello,

Super new to C.

Can someone explain why the following runs, but does not perform the arithmetic operators? (Note: some of the variables initialized are for a later part of the program.)

Code:
```#include <stdio.h>

int main(void)
{
float hoursWorked;
float hourlyWage;
float basePay;
float otPay;
float grossPay;
float netPay;
float taxBurden;
float baseTax = 0.15;
float progressiveTax = 0.20;

basePay = hoursWorked * hourlyWage;
otPay = (hoursWorked - 40) * hourlyWage * 0.5;
grossPay = basePay + otPay;

printf("This program will calculate your Gross Pay, Net Pay, and Tax Burden based on your hours worked and wage.\n\n");
printf("Please enter hours worked this week and your hourly wage separated by a comma.\n\n");
scanf("%.2f , %.2f", hoursWorked, hourlyWage);

if (hoursWorked == 0)
printf("No pay for you, slacker!");

if (hoursWorked <= 40 && !0)
printf("Your gross pay is: %.2f", basePay);

if (hoursWorked >40)
printf("Your gross pay is: %.2f", grossPay);

return 0;
}```

2. For C, the statements are run in the same order they appear in the code. So you should do the calculations after you ask for the inputs.

Also this doesn't mean what you think it does:

Code:
`if (hoursWorked <= 40 && !0)`

3. Hmm. I changed the order and same results.

It prints the "Your gross pay is: ", but all results are 0.00, no matter the inputs.

4. Code:
```\$ gcc -Wall main.c
main.c: In function ‘main’:
main.c:21:11: warning: unknown conversion type character ‘.’ in format [-Wformat=]
scanf("%.2f , %.2f", hoursWorked, hourlyWage);
^
main.c:21:11: warning: unknown conversion type character ‘.’ in format [-Wformat=]
main.c:21:11: warning: too many arguments for format [-Wformat-extra-args]
main.c:13:11: warning: unused variable ‘progressiveTax’ [-Wunused-variable]
float progressiveTax = 0.20;
^
main.c:12:11: warning: unused variable ‘baseTax’ [-Wunused-variable]
float baseTax = 0.15;
^
main.c:11:11: warning: unused variable ‘taxBurden’ [-Wunused-variable]
float taxBurden;
^
main.c:10:11: warning: unused variable ‘netPay’ [-Wunused-variable]
float netPay;
^
main.c:15:13: warning: ‘hoursWorked’ is used uninitialized in this function [-Wuninitialized]
basePay = hoursWorked * hourlyWage;
^
main.c:15:13: warning: ‘hourlyWage’ is used uninitialized in this function [-Wuninitialized]```
One big problem is that you're not passing variable addresses to scanf.

5. One big problem is that you're not passing variable addresses to scanf.
Thank you for responding. Could you please explain more? Why isn't my scanf line sufficient? In my thinking, it scans for what the user will input. The other variables are calculations to be created. Where am I thinking incorrectly?

6. Like this.
Code:
`scanf("%f , %f", &hoursWorked, &hourlyWage);`
Also, if you leave the comma in the format string, then you REALLY do have to type in a comma yourself.

So most people generally go with
Code:
`scanf("%f %f", &hoursWorked, &hourlyWage);`
Also, C doesn't revise the past, so you need your calculations AFTER the input.

Code:
```    scanf("%f %f", &hoursWorked, &hourlyWage);

basePay = hoursWorked * hourlyWage;
otPay = (hoursWorked - 40) * hourlyWage * 0.5;
grossPay = basePay + otPay;```

7. Originally Posted by Salem

Also, C doesn't revise the past, so you need your calculations AFTER the input.
All of that actually made sense to me! :-D

Thank you!