So I am confused on where I should start here I believe that I start with an if statement after the cin << price function what do you guys believe I should do from there i'm going to continue working on it and I will update the coding so that if there are any mistake I can get insight on the coding thank you very much.
Complete the program so it will correctly compute the price for an item that may or may not include sales tax. The program asks the user for the type of item (1 for food, 2 for non-food) and the price of the item.
The finished version should only display any calculations if the price entered is a non-zero, positive number. For a positive price of a non-food item, compute the 6% sales tax, add it to the original price. For a positive price of a food item, it doesn’t need to calculate anything.
Your program should display an error message for a zero or negative price and type not equal to 1 or 2. Only if there are no errors, it should display the amount of tax and the new price that must be paid.
amount of tax = original price * tax rate
final price = original price + amount of tax
When you are finished with the program submit it and update the comments at the top of the program. Here are some test cases to verify your output.
Test Case #1
Inputs: type = 1, price = 13.69
Outputs: tax = $0, final price = $13.69
Test Case #2
Inputs: type = 2, rate = 13.69
Output: tax = $0.82, final price = $14.51
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
|
#include <iostream>
using namespace std;
int main()
{
//declare variables
double price = 0.0;
const double TAX = 0.06;
double totalPrice = 0.0;
int type = 0;
cout << fixed; //set precision of output
cout << precision(2);
//enter input
cout << "Enter type of item (1=food, 2=non food): ";
cin >> type;
cout << "Enter the price of item: ";
cin >> price;
//check for positive #'s for price and type of 1 or 2
//compute tax and add to price if applicable
//display output
//display error message for incorrect values
return 0;
} //end of main function
|