calculating total

hi everyone i'm having trouble calculating the total in my program. could anyone give me a hand? thanks alot.

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int linearSearch (string [], int, string);
int main ()

{
cout << "the available commands are \n\n";
cout << "/rawprices, this is the first command needed when making an invoice.";
cout << " Here the \nproduct and price are entered\n\n";

cout << "/items is the seccond command used when making an invoice.\n";
cout << "The item name and then quantity are entered\n\n";

cout << "/invoice, once all data has been entered the user enters this\n";
cout << " command to view the outputed invoice\n\n";

cout << "/ this command exits the program\n\n";

cout << "please input one of the available commands: ";

string item[100];
string products[200];
double prices[200];
string str;
int numPurchase = 0;
int numProd = 0;
int quantity[100];
double total;
cin>> str;




if( str == "/rawprices")
{
cout << "\n\nenter the items name and then price\n";
cout << "for example type dog 1 and then press enter\n\n";
cout << "enter items and their prices one at a time, you can enter as many items\n";
cout << "as you like\n\n";
cin >> str;

while( str[0] !='/')
{
products[numProd] = str;
cin>> prices[numProd];
numProd++;
cin >> str;

}
}

if( str == "/items")
{
cout << "\n\nnow enter the products name and how many items\n\n";
cout << "for example dog 50 and then press enter\n\n";
cin >> str;

while( str[0] !='/')
{

item[numPurchase] = str;
cin>> quantity[numPurchase];
numPurchase++;
cin >> str;
}
}

if (str == "/invoice")

cout << "phantom company invoice\n\n";
cout << "PRODUCT ID" << setw(13) << "QUANTITY" << setw(11) << "PRICE ($)" << setw(13) << "COST($)" << setw(11) <<"\n";

int locations;
double price;
double cost;

for (int i=0; i<numPurchase; i++)

{
cout << item[i] <<setw(17) << fixed << setprecision(0) << quantity[i];





int location = linearSearch (products, numProd, item[i]);

price = prices[location];

cost = price * quantity[i];



cout << setw(10) << fixed << setprecision(0)<< price;
cout << setw(13) << fixed << cost << endl;

total = cost + cost;
}


cout << "\n\n\nTOTAL PRICE($) =" << total;


system ("pause");
return 0;
}
int linearSearch(string list[], int size, string key)
{
int i;
for (i = 0; i < size; i++)
{if (list[i] == key)
return i;
}
return -1;
}
Don't post multiple topics, it wastes forum space.

Anyway, that if statement if(str == "/invoice") does not have an opening bracket. That might be why it isn't working.
Sorry my web browser froze and i was unsure that the post worked.

I tried changing that like you suggested but still i cant get an accurate total!!!

Please anyone lol?
In general, there is one significant problem with the program, and the problem is that you can only choose one of the options once. You need to make the main menu a loop so that the user can, for instance, select the items command twice and enter two different types of items. Also, the line
 
total = cost + cost;

simply sets the total to twice the most recent cost. Instead, you should be increasing the total by the most recent cost, which would be coded
 
total = total + cost;

But the most important thing is that you fix the main menu so that it loops.
Topic archived. No new replies allowed.