Write a program to compute the subtotal, tax(8% of subtotal) and total an order.
ID: 3763825 • Letter: W
Question
Write a program to compute the subtotal, tax(8% of subtotal) and total an order.
The program will first ask for numbers of items in the oreder.
The program will read in the price for each item(use a controlled for-loop).
The program will compute and output the subtotal, tax, and the toal amout for the order.
Sample Output:
>a.out
How many items are in the order: 4
Enter the price of an item: 3.99
Enter the price of an item: 7.99
Enter the price of an item: 12.50
Enter the price of an item: 2.79
Subtotal: $27.27
Sales Tax: $2.18
Total: $29.45
Explanation / Answer
#include <stdio.h>
int main()
{
int no_items,i;
float price,subtotal,tax,total;
const float TAX_PERC=0.08;
printf("How many items are in the order: ");
scanf("%i", &no_items);
subtotal=0;
i=0;
for (i=0;i<no_items;i++){
printf("Enter the price of an item: ");
scanf("%f",&price);
subtotal=subtotal+price;
}
tax=subtotal*TAX_PERC;
total=subtotal+tax;
printf("Subtotal: $%.2f ",subtotal);
printf("Sales Tax: $%.2f ",tax);
printf("Total: $%.2f ",total);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.