Pretty simple program.
The program runs fine.
Do you think the program is acceptable considering the parameters set by the instructions?
Create a small program based on the following
// encourage the use of user-defined functions
// (calculates different sales tax based on an item price)
1. Ask the user to enter the price of an item.
2. Get the item price from the user.
3. Calculate the sales tax of the item:
- 7% if the item costs less than $200.
- 5% if the item costs $200 or more.
4. Display the original item price and sales tax amount onto the screen.
5. Calculate new cost of the item with the sales tax.
6. Display the total price of the item onto the screen.
Code:
#include<stdio.h>
#include<math.h>
double getPrice(void);
int main(void){
double price = 0.0;
double sevenP = 0.0;
double fiveP = 0.0;
printf("PLease enter the price of the customers purchase:\t$");
price = getPrice();
printf("The price is:\t $ %.2lf\n", price);
sevenP = price * .07;
fiveP = price * .05;
if (price < 200){
printf("The federal tax is: $ %.2lf\n", sevenP);
printf("The price plus the federal tax is: $ %.2lf\n", sevenP + price);
}else{
printf("The state tax is: $ %.2lf\n", fiveP);
printf("The price plus the state tax is: $ %.2lf\n", fiveP + price);
}
return 0;
}
double getPrice(void){
int value = 0;
scanf_s(" %d", &value);
return value;
}