ReMaKe - 1 year ago 104
C++ Question

# Calculating sales tax, and total

I've been coding for a few days now and decided to take on an exercise. One which calculates the total of five items and calculates the tax.
In this particular exercise, I've managed to display the names of the items, and their prices , however, the sales tax and total aren't being displayed. I know this is a very basic problem, I've just been trying to get some hands on and learn, familiarize myself a bit more by trial and error. Can anyone pinpoint what I'm missing as far as the calculation part goes? Thanks advance.

``````#include <iostream>
using namespace std;

float tax = 0.07;
string item1,item2,item3,item4,item5;
float price1,price2,price3,price4,price5;

int main()
{
cout<<" please enter the name of the first item \n";
cin>> item1;

cout<<" please enter the name of second item \n";
cin>> item2;

cout<<" plrease enter the name of the third item \n";
cin>> item3;

cout<<" please enter the name of the fourth item \n";
cin>> item4;

cout<<" please enter the name of the fifth item \n";
cin>> item5;

cout<<" please enter the price for the first item \n";
cin>> price1;

cout<<" please enter the price for the second item \n";
cin>> price2;

cout<<" please enter the price for the third item \n";
cin>> price3;

cout<<" please enter the price for the fourth item \n";
cin>> price4;

cout<<" please enter the price for the fifth item \n";
cin>> price5;

float subtotal = 0;
float saletax = 0;
float grandtotal = 0;

subtotal = price1 + price2 + price3 + price4 + price5;
saletax = subtotal * tax;
grandtotal = subtotal + saletax;

cout<<"my shopping list \n";
cout<<"================\n";

cout<<item1<<"     "<<"\$"<<price1 <<endl;
cout<<item2<<"     "<<"\$"<<price2 <<endl;
cout<<item3<<"     "<<"\$"<<price3 <<endl;
cout<<item4<<"     "<<"\$"<<price4 <<endl;
cout<<item5<<"     "<<"\$"<<price5 <<endl;
``````

``````cout << "Total: " << grandtotal << endl;