Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
C program skipping a scanf for a float?
Everytime I go to the option to enter the costs it skips the float inputs.. URGENT...
Code:
void service_cost(void)
{
float hwcost;
float swcost;
float tcost=0.00;
float labourcost;
FILE *fp2;
printf("\t*********************************************************************\n"); //printf statement
printf("\t*********************************************************************\n"); //printf statement
printf("\t*** Service Account ***\n"); //printf statement
printf("\t*********************************************************************\n"); //printf statement
printf("\t*********************************************************************\n\n\n");//printf statement
printf("Please enter hardware cost\n");
scanf("%.2f", &hwcost);
printf("Please enter the software cost\n");
scanf("%.2f",&swcost);
printf("Please enter the labour cost\n");
scanf("%.2f",&labourcost);
tcost = (tcost + hwcost + swcost + labourcost);
printf("The total service cost is %.2f\n", &tcost);
fp2=fopen(Services,"a+");
fprintf(fp2,"The hardware cost is: %.2f\n",hwcost); //writes to file
fprintf(fp2,"The software cost is: %.2f\n",swcost); //writes to file
fprintf(fp2,"The labour cost is: %.2f\n",labourcost); //writes to file
fprintf(fp2,"The overall cost is: %.2f\n", tcost);
fprintf(fp2,"................................................\n");
fclose(fp2); //close file
system("PAUSE");
system("cls");
serviced();
}
1 Answer
- RatchetrLv 71 decade agoFavorite Answer
In your scanf calls, just use %f rather than %.2f
The . and 2 are format specifiers that printf recognizes, but not scanf.
Also, in this line:
printf("The total service cost is %.2f\n", &tcost);
Drop the &. You don't want the address of tcost, just the value.