Description To make a profit, a local store marks up the prices of its items by
ID: 3919133 • Letter: D
Question
Description To make a profit, a local store marks up the prices of its items by a certain percentage. Write a program that reads the original price of the item sold (double) and the percentage of the marked-up price (double) The program then outputs the original price of the item, the percentage of the mark-up, the store's selling price of the item, the sales tax rate (you will have a constant that holds 7.25%), the amount taxed, and then the final amount of the item. (The final price is the store's selling price plus tax) Specifications In order to get full credit, you will need to have/perform in your code Variable with correct types and meaningful names Comments in your code for variables and for blocks of code that perform input, output, and calculations . Use iomanip to format all numbers to two decimal places and nicely aligned . Program must compile and run with any input Program must re-prompt the user if invalid input is entered (non positive number entered or a non number entered This program wl be menu driven, at the end of each iteration, the program needs to prompt the user to continue or quit You will modify the previous assignment (assignment 4) to make it menu driven and will re-prompt the user if they enter non positive numbers or strings (you may need to use cin.clear) and cin.ignore (100, n) on input failure), and you will output all the values like before but you will keep running the code until the user decides they want to quit. You can compare characters the same way you compare integers, you want to make your code case insensitive so you can use toupper (charVariable) or tolower(charVariable) which just returns the upper or lower case version of a character Sample Output Jimis-MacBook-Pro Asst06 VaskoDaGamer g+ Asst06.cpp Jimis-MacBook-Pro: Asst06 VaskoDaGamer? ,/a.out Please enter item 's sale price 29.9Explanation / Answer
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks
//Code
#include<iostream>
#include<iomanip>
#include<ctype.h>
#define TAX_RATE 7.25
using namespace std;
//method to prompt for a positive double value, validate and return it
double getValue(string prompt){
cout<<prompt<<": ";
double input;
//getting input
cin>>input;
//validating input
if(cin.fail()){
cin.clear();
cin.ignore(100,' ');
cout<<"Invalid input, try again..."<<endl;
//asking again
return getValue(prompt);
}
if(input<0){
cout<<"Only positive values are allowed, try again..."<<endl;
//asking again
return getValue(prompt);
}
//valid value, returning
return input;
}
//method to print the stats in proper format
void printStats(double original,double markup,double selling,double amount_tax,double final){
//using iomanip functions and attributes, displaying each value in a properly
//formatted manner
cout<<setw(25)<<setfill('.')<<left<<"Original price"<<"$"<<setfill(' ')
<<setw(8)<<right<<setprecision(2)<<fixed<<original<<endl;
cout<<setw(25)<<setfill('.')<<left<<"Mark-up percentage"<<" "<<setfill(' ')
<<setw(8)<<right<<setprecision(2)<<fixed<<markup<<endl;
cout<<setw(25)<<setfill('.')<<left<<"Selling price"<<"$"<<setfill(' ')
<<setw(8)<<right<<setprecision(2)<<fixed<<selling<<endl;
cout<<setw(25)<<setfill('.')<<left<<"Sales tax"<<"$"<<setfill(' ')
<<setw(8)<<right<<setprecision(2)<<fixed<<TAX_RATE<<"%"<<endl;
cout<<setw(25)<<setfill('.')<<left<<"Amount taxed"<<"$"<<setfill(' ')
<<setw(8)<<right<<setprecision(2)<<fixed<<amount_tax<<endl;
cout<<setw(25)<<setfill('.')<<left<<"Final price"<<"$"<<setfill(' ')
<<setw(8)<<right<<setprecision(2)<<fixed<<final<<endl;
}
int main(){
double original_price,marked_up_percent,selling,tax_amount,final;
char choice='Y';
//looping until user choice is not y or Y
while(toupper(choice)=='Y'){
//getting inputs
original_price=getValue("Enter item's sale price");
marked_up_percent=getValue("Enter mark up percentage");
//calculating values
selling=original_price+(original_price*marked_up_percent/100.0);
tax_amount=selling*TAX_RATE/100.0;
final=selling+tax_amount;
//printing stats
printStats(original_price,marked_up_percent,selling,tax_amount,final);
//prompting again
cout<<" Do you wish to continue? (Y/N): ";
cin>>choice;
}
return 0;
}
/*OUTPUT*/
Enter item's sale price: 29.99
Enter mark up percentage: 12.99
Original price...........$ 29.99
Mark-up percentage....... 12.99
Selling price............$ 33.89
Sales tax................$ 7.25%
Amount taxed.............$ 2.46
Final price..............$ 36.34
Do you wish to continue? (Y/N): y
Enter item's sale price: x
Invalid input, try again...
Enter item's sale price: -25
Only positive values are allowed, try again...
Enter item's sale price: 200
Enter mark up percentage: 10.998
Original price...........$ 200.00
Mark-up percentage....... 11.00
Selling price............$ 222.00
Sales tax................$ 7.25%
Amount taxed.............$ 16.09
Final price..............$ 238.09
Do you wish to continue? (Y/N): y
Enter item's sale price: seven
Invalid input, try again...
Enter item's sale price: 7.99
Enter mark up percentage: 9.9
Original price...........$ 7.99
Mark-up percentage....... 9.90
Selling price............$ 8.78
Sales tax................$ 7.25%
Amount taxed.............$ 0.64
Final price..............$ 9.42
Do you wish to continue? (Y/N): n