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;
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;
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;
}
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.