What is wrong with this code? //-------------------------------------------- //f
ID: 3573024 • Letter: W
Question
What is wrong with this code?
//--------------------------------------------
//file name: price.c
//programmer: morgan lim
//date: december 5, 2016
//
//description:
//allows the user to input a number of seconds
//and converts it to hours and minutes. the user
//can do this over and over until a value of 0
//or less is entered.
//--------------------------------------------
//preprocessor directives
#include <stdio.h>
#define AFTERTAX 1.056
int main()
{
double beforet, aftert;
int dollars, cents;
printf("Enter the price of your item.");
scanf("%lf" &beforet);
aftert = beforet*AFTERTAX;
dollars = aftert;
cents = (aftert - dollars) * 100;
printf("The price of your item is %.2lf."
"The price of your item plus tax is %d dollars and %2d cents.",
beforet, beforet, aftert);
getchar();
getchar();
return 0;
}
Explanation / Answer
Hi
I have updated the code and highlighted the code changes below
#include <stdio.h>
#define AFTERTAX 1.056
int main()
{
double beforet, aftert;
int dollars, cents;
printf("Enter the price of your item.");
scanf("%lf" ,&beforet);
aftert = beforet*AFTERTAX;
dollars = aftert;
cents = (aftert-beforet) * 100;
printf("The price of your item is %.2lf. "
"The price of your item plus tax is %d dollars and %d cents. ",
beforet, dollars, cents);
getchar();
return 0;
}
Output:
sh-4.2$ gcc -o main *.c
sh-4.2$ main
Enter the price of your item.900
The price of your item is 900.00.
The price of your item plus tax is 950 dollars and 5040 cents.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.