In: Computer Science
Hello, this question relates to a class I am taking called introduction to C++. I have no experience writing programs and outside of learning out of a textbook, and studying on my own, have little understanding of logic. I have been assigned a problem that requires me to write a program for a Grocery Bill, where the consumer inputs the price for 5 items, that the program calculates the total with a 6% sales tax. I really am not sure where to start for this exercise. Here is the assignment word for word:
"For this assignment, write a program that calculates a grocery bill. The program should output “Joe’s Market” as the title. The program should prompt the user to enter the price for five products of your choosing. The program should calculate the total price of the groceries, add 6% sales tax to the groceries, and display the total price including sales tax. Be sure to include comments throughout your code where appropriate."
Bill.cpp
#include<iostream>
using namespace std;
// main function
int main()
{
// variables declaration
double
keyboard,mouse,monitor,hardDisk,panDrive,totalPrice,netPrice,tax;
cout<<"*** Welcome To Joe's Market
***"<<endl<<endl;
// accept prices for 5 product from user
cout<<"Enter the price of Keyboard: ";
cin>>keyboard;
cout<<"Enter the price of Mouse: ";
cin>>mouse;
cout<<"Enter the price of Monitor: ";
cin>>monitor;
cout<<"Enter the price of Hard Disk: ";
cin>>hardDisk;
cout<<"Enter the price of Pan Drive: ";
cin>>panDrive;
// calculate total price of 5 products
totalPrice=keyboard+monitor+mouse+panDrive+hardDisk;
// calculate 6% sales tax
tax=totalPrice*6/100;
// calculate net total
netPrice=totalPrice+tax;
// print bill
cout<<endl<<endl<<"**************************************"<<endl;
cout<<"*** Joe's Market ***"<<endl;
cout<<"**************************************"<<endl;
cout<<"Keyboard:
"<<keyboard<<endl;
cout<<"Mouse: "<<mouse<<endl;
cout<<"Monitor:
"<<monitor<<endl;
cout<<"Hard Disk:
"<<hardDisk<<endl;
cout<<"Pan Drive:
"<<panDrive<<endl;
cout<<"**************************************"<<endl;
cout<<"Total:
"<<totalPrice<<endl;
cout<<"6% Sales Tax:
"<<tax<<endl;
cout<<"**************************************"<<endl;
cout<<"Net Total:
"<<netPrice<<endl;
cout<<"**************************************"<<endl;
return 0;
}
Output