In: Computer Science
Make a program that calculates the total of a retail sale. The program should ask the user for the following: the retail price of the item being purchased and the sales tax rate. Once the information has been entered, the program should calculate and display the following: the sales tax for the purchase and the total sale.
CODE IN C++->
#include <iostream>
#include <iomanip>
int main()
{
// ask user for retail price of item purchased
std::cout << "please enter the retail price of item purchased: " ;
// read the user input into a variable
double retail_price ;
std::cin >> retail_price ;
// ask user for sales tax rate
std::cout << "please enter the sales tax rate as a percentage: " ;
// read the user input into another variable
double percent_sales_tax ;
std::cin >> percent_sales_tax ;
// if the retail price and sales tax rate are positive values
if( retail_price > 0 && percent_sales_tax > 0 )
{
// compute sales tax amount
const double sales_tax_amount = retail_price * percent_sales_tax / 100.0 ;
// calculate total amount
const double gross_amount = retail_price + sales_tax_amount ;
// display on screen the sales tax amount for purchase and the total.
std::cout << std::fixed // fixed point format,
<< std::setprecision(2) // with two digits after the decimal point
<< "sales tax amount: " << sales_tax_amount << '\n'
<< " total amount: " << gross_amount << '\n' ;
}
else std::cout << "there was an error in the data that was entered.\n" ; // invalid input
}
OUTPUT->
NOTE->
FOR ANY DOUBTS AND QUERIES PLEASE COMMENT AND IF YOU LIKED MY
ANSWER PLEASE UPVOTE.