I have been working on a code that I found on line and trying to add sales tax to it but every time I run the program the sales tax isn’t completely correct and I’m also missing decimals after the final total. Here’s a screen show of the program when finished showing the issues along with the code.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//declare arrays
string itemName[100];
double itemCost[100] = { 0.0 };
const double saleTax = 0.07;
//declare variables
string names = "";
double total = 0.0;
int numItems = 0;
//number of items
cout << "Enter number of grocery items you will be entering: ";
cin >> numItems;
for (int i = 1; i >= 100; i++)
{
cin >> itemName[i] >> itemCost[i];
}
//input message
cout << "Please enter the item names as one word only.Example: tomatoes\n";
cout << "Enter the cost as a decimal number.Example: 2.44\n\n";
//item name and price input
for (int sub = 1; sub <= numItems; sub += 1)
{
cout << "Enter item " << sub << ":";
cin >> itemName[sub];
cout << "Enter the cost of the " << itemName[sub] << ":";
cin >> itemCost[sub];
}
cout << "Items" << " " << "Cost" << endl;
//Display Data
for (int i = 1; i <= numItems; ++i)
{
cout << itemName[i];
cout << ' ';
cout << "$" << itemCost[i];
cout << endl;
}// end for
for (int i = 1; i <= 100; ++i)
{
total = (total + itemCost[i]);
}
int Tax = total * saleTax;
int Grandtotal = total + Tax;
cout << "Sale Tax : " << Tax << endl; cout << "Grocery : " << total << endl;
cout << "Total:$" << Grandtotal << endl;
system("PAUSE");
return 0;
}