In: Computer Science
A customer in a grocery store is purchasing three items. Write the pseudo code that will:
• Ask the user to enter the name of the first item purchased. Then ask the user to enter the cost of the first item purchased. Make your program user friendly. If the user says the first item purchased is milk, then ask: “What is the cost of milk.” [This should work no matter what item is entered by the user. I might buy candy rather than milk.]
• Ask the user to enter the name and cost of the second item purchased.
• Ask the user to enter the name and cost of the third item purchased.
• Calculate the amount of sales tax due on the total purchase price. The sales tax rate is 5%.
• Tell the user • The name and price of each item entered
• The total cost of the items purchased • The amount of sales tax due on the total purchase.
• The total amount due from the user [total cost plus sales tax] • Hint: Your first line of code should be: constant real SALES_TAX_RATE = .05;
Structure your code as follows: 1. Declare variables 2. Get user input 3. Do calculations. 4. Output what is required
Idk if its c or c++ but this is an example I have, need it to be written like that
// declare variables
Real totalSales;
Real profits;
// get user input
print "Enter amount of total sales";
totalSales = User Input;
// do calculations
profit = totalSales * .10;
// output
print "Your profit is", profit;
#include<iostream>
using namespace std;
int main()
{
const double SALES_TAX_RATE =.05;
string item1,item2,item3;
double cost1,cost2,cost3;
//reading input
cout<<"Enter name of item:";
cin>>item1;
cout<<"Enter cost of
"<<item1<<":";
cin>>cost1;
cout<<"Enter name of item:";
cin>>item2;
cout<<"Enter cost of
"<<item2<<":";
cin>>cost2;
cout<<"Enter name of item:";
cin>>item3;
cout<<"Enter cost of
"<<item3<<":";
cin>>cost3;
//computing displaying output
cout<<item1<<" cost
:"<<cost1<<endl;
cout<<item2<<" cost
:"<<cost2<<endl;
cout<<item3<<" cost
:"<<cost3<<endl;
double TotalSales = cost1+cost2+cost3;
cout<<"Total cost of items purchased
:"<<TotalSales<<endl;
double SalesTax = TotalSales*SALES_TAX_RATE;
cout<<"The amount of sales tax due on the total
purchase :"<<SalesTax<<endl;
cout<<"The total amount due from the user
:"<<TotalSales+SalesTax<<endl;
return 0;
}
output:
Enter name of item:milk
Enter cost of milk:100
Enter name of item:cofee
Enter cost of cofee:120
Enter name of item:pepsi
Enter cost of pepsi:20
milk cost :100
cofee cost :120
pepsi cost :20
Total cost of items purchased :240
The amount of sales tax due on the total purchase :12
The total amount due from the user :252
Process exited normally.
Press any key to continue . . .