error in my code
Feb 25, 2017 at 10:38am
i have done the code. But when running it, it cannot do more than 3 instruction. Please help. Thnx in advance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <stdio.h>
int main()
{
int id;
float hour,hourrate;
float gross,net;
float averagepay;
printf("Salary Calculator:\n");
printf("\tPlease insert identification number:");
scanf("%d",& id);
printf("\tPlease insert your hourly wage rate:");
scanf("%.2f",& hourrate);
printf("\tPlease insert your number of hours worked:");
scanf("%.2f",& hour);
if (hour<=40)
{
gross=hour*hourrate;
return 0;
}
else
if(hour>40)
{
gross=40*hourrate+(hour-40)*hourrate*0.5;
return 0;
}
net=gross-(gross*3.625/100);
averagepay=net/7;
printf("%d\n",id);
printf("\toverall total net pay:%.2f\n",net);
printf("\taverage net pay:%.2f\n",averagepay);
getchar();
return 0;
}
|
Feb 25, 2017 at 11:11am
What errors did you get? I slightly modified your code just to examine it and it seems fine:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <cstdio>
int main()
{
printf("Salary Calculator:\n");
printf("\tPlease insert identification number: ");
int id;
scanf("%d", &id);
printf("\tPlease insert your hourly wage rate: ");
float hourrate;
scanf("%f", &hourrate);
printf("\tPlease insert your number of hours worked: ");
float hour;
scanf("%f", &hour);
float gross;
if (hour<=40)
{
gross=hour*hourrate;
}
else
{
gross=40*hourrate+(hour-40)*hourrate*0.5;
}
float net = gross-(gross*3.625/100);
float averagepay=net/7;
printf("\n%d:\n", id);
printf("\toverall total net pay: %.2f\n", net);
printf("\taverage net pay: %.2f\n", averagepay);
getchar();
return 0;
}
|
Please, clarify better your issue.
Feb 25, 2017 at 1:46pm
i run the program. the program cannot run more than three lines of command. until
|
printf("\t Please insert your hourly wage rate:");
|
Feb 27, 2017 at 5:42am
i think i found the problem.
i put .2f in the scanf("%.2f",hourrate). That is the problem. After omit it, it seems fine.
Topic archived. No new replies allowed.