#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
int linearSearch (string [], int, string);
int main ()
{
cerr << "the available commands are \n\n";
cerr << "/rawprices, this is the first command needed when making an invoice.";
cerr << " Here the \nproduct and price are entered\n\n";
cerr << "/items is the seccond command used when making an invoice.\n";
cerr << "The item name and then quantity are entered\n\n";
cerr << "/invoice, once all data has been entered the user enters this\n";
cerr << " command to view the outputed invoice\n\n";
cerr << "/ this command exits the program\n\n";
cerr << "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")
{
cerr << "\n\nenter the items name and then price\n";
cerr << "for example type dog 1 and then press enter\n\n";
cerr << "enter items and their prices one at a time, you can enter as many items\n";
cerr << "as you like\n\n";
cin >> str;
while( str[0] !='/')
{
products[numProd] = str;
cin>> prices[numProd];
numProd++;
cin >> str;
}
}
if( str == "/items")
{
cerr << "\n\nnow enter the products name and how many items\n\n";
cerr << "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];
total = cost + cost;
cout << setw(10) << fixed << setprecision(0)<< price;
cout << setw(13) << fixed << cost;
}
}
cout << setw(32) << "\n\n\nTOTAL COST = $" << 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;
}