Y
yxxxxy
Hi, this is a part of my program code.
i want to ask two questions.
int time;
float rate;
float salary;
printf("Enter # of hours worked (-1 to end):");
scanf("%d",&time);
while (time!=-1) {
printf("Enter hourly rate of the worker ($00.00):");
1 scanf("%f",&rate);
if (time>=40)
2 salary=(time-40)*3/2*rate+40*rate;
else
salary=time*rate;
printf("Salary is $%.2f\n",salary);
printf("Enter # of hours worked (-1 to end):");
scanf("%d",&time);
}
first question:
there is no error and warning.
but
when i change 3/2 to 1.5 (line 1), it will reveals a
warning :conversion from 'double' to 'float', possible loss of data
why?
second question:
when i change "%f" to " %f",there is no change in result.
but when i change it to "%f " , it will stop at this line .
and when i change it to "% f",it will output a wrong num and not let
me print second time .
why?
my english is not good,if i didn't express my idea clearly ,please
forgive me.
Thank you very much.
i want to ask two questions.
int time;
float rate;
float salary;
printf("Enter # of hours worked (-1 to end):");
scanf("%d",&time);
while (time!=-1) {
printf("Enter hourly rate of the worker ($00.00):");
1 scanf("%f",&rate);
if (time>=40)
2 salary=(time-40)*3/2*rate+40*rate;
else
salary=time*rate;
printf("Salary is $%.2f\n",salary);
printf("Enter # of hours worked (-1 to end):");
scanf("%d",&time);
}
first question:
there is no error and warning.
but
when i change 3/2 to 1.5 (line 1), it will reveals a
warning :conversion from 'double' to 'float', possible loss of data
why?
second question:
when i change "%f" to " %f",there is no change in result.
but when i change it to "%f " , it will stop at this line .
and when i change it to "% f",it will output a wrong num and not let
me print second time .
why?
my english is not good,if i didn't express my idea clearly ,please
forgive me.
Thank you very much.