Here is my problem, if you run the program(using piping), it should output the followings:

=========================
PHANTOM COMPANY INVOICE

PRODUCT ID	QUANTITY  PRICE ($)    COST ($)
P010001		   2	     24.99	 49.98
DVD-player5	   1	     58.95	 58.95
P010002		  20	      8.85	177.00
...
	TOTAL COST = $xxxxx.xx

my invoice is not the same as the output, I know that there is something wrong with my code, but just can't figure it out!

I know this sounds dull, I just starting to learn c++ and I would be appreciated, If someone
could help me figure out what's wrong.

Attachments
/rawprices
P010001		24.99	
QX-35		19.99	
DVD-player5	58.95	
P010002		 8.85	
P010003		35.00

/items
P010001		2
DVD-player5	1
P010002		20

/invoice
/quit
#include <iostream> 
#include <iomanip>
#include <string>
#include "windows.h" 
using namespace std;
//global
    const int lim = 2000;
    string cmd;
    string product[lim];
    double price[lim];
    int i, quan[lim];
void title();
string Price(string product[], double price[]);
string Quantity(string product[], int quan[]);

void invoice(string product[], int quan[], double price[]);
// main
int main(){
    string cmd;
    string product[lim];
    double price[lim];
    int quan[lim];
    
    // the outlook
    input:
          title();
            
    system("pause");
    return 0;
}
    
   //function of title
void title(){
     input:     
     cerr << "***************************************************************"
         << "\n*   Use the following commands to input data                  *" 
         << "\n*   /items     - only contains productid and quantity         *"
         << "\n*   /rawprices - only contains productid and price            *"
         << "\n*   /invoice   - print out a detailed invoice on the screen   *"
         << "\n*   /quit      - exit the program                             *"
         << "\n***************************************************************"; 
    
         cerr << "\n <\\: ";
         cin >> cmd;
    
    //command for /rawprices
    if (cmd == "/rawprices"){  
        cerr << Price(product, price) << endl;
    }
    
    //command for /items
    else if (cmd == "/items"){  
        cerr << Quantity(product, quan) << endl;
    }
    
    //command for /invoice
    else if (cmd == "/invoice"){
     invoice(product, quan, price);
    }
     
    //command for /quit
    else if (cmd == "/quit"){
     exit (1);
     }
 
    //command valiation
    else {
       cerr << "Invalid command" << endl;
       cerr <<"Try again" << endl;
       Sleep (1000);
       system("cls");
       goto input;
    }
}


   //function of price
string Price(string product[], double price[]){
    int i;
    string id;
    cerr << "\t Now you can enter data, to switch to different function"
          << "\n\t just enter any of the command."<< endl;
    cerr << "\t Productid allows 2000 items"<< endl;
    
  for (int i = 0; i<lim; i++){
    
    cerr << "product id: " ; cin >> product[i];
    if ( product[i] < "/" || product[i] > ":" && 
          product[i] < "A" || product[i] > "Z" &&
          product[i] < "a" || product[i] > "z"){      
     cerr << "only supports alphanumeric format, try again: " << endl;
     cin >> product[i];
     }    
    else if (product[i] == "/invoice"){
     invoice(product, quan, price); 
    }
    else if (product[i] == "/items"){
    Quantity(product, quan);       
    }
    else if (product[i] == "/"){
    cerr << "that is a command";
    exit (1);}
    else {
    cerr << "$ "; cin >> price[i];
    }
  } 
return id;
}
    // function of quantity
string Quantity(string product[], int quan[]){
    int g;
    string idd;
    
    cerr << "\t Now you can enter data, to switch to different function"
         << "\n\t just enter any of the command."<< endl;
    cerr << "\t Productid allows 2000 items"<< endl;    
    cerr << "\t and Quanity limits at 1000."<< endl;
  for (int g = 0; g< lim; g++){
    cerr << "product id: " ; cin >> product[g];
    
     if ( product[g] < "/" || product[g] > ":" && 
          product[g] < "A" || product[g] > "Z" &&
          product[g] < "a" || product[g] > "z"){      
     cerr << "only supports alphanumeric format, try again: " << endl;
     cin >> product[g];
     }                 
    else if (product[g] == "/invoice"){
     invoice(product, quan, price); 
    }
    else if (product[g] == "/rawprices"){
    Price(product, price);       
    }
    else if (product[g] == "/"){
    cerr << "that is a command";
    exit (1);
    }
    else {
    
    cerr << "Number of items "; cin >> quan[g];
    
    if(quan[g] > 1000){
    cerr << "1000 is the maximum number for items, try again" << endl;
    cin >> quan[g];
    }}   
  }  
return idd;
}

    // function of invoice
void invoice(string product[], int quan[], double price[]){
     cerr << "result: " << endl;  
     cerr << "\t\t PHANTOM COMPANY INVOICE " << endl;
     cerr << endl;
     cerr << "PRODUCT ID" << setw(15) << "QUANTITY" << setw(18) << "PRICE ($)  "
          << setw(12) << "COST ($)" << endl;
     double TL;
     int g=0;
     for (int i=0; i< 3; g++, i++){
         if(product[i]== product[g]){
          cerr <<" " << product[g] << "\t\t"<< quan[g] << "\t  "
          <<  i << "\t\t" << quan[g]*price[i] << endl;
          TL =  TL + quan[g]*price[i];
          }
      
      }
     cerr << "total = " << TL << endl;
     
     title();
}

this is the code for someone who trying to download the file.

#include <iostream> 
#include <iomanip>
#include <string>
#include "windows.h" 
using namespace std;
//global
    const int lim = 1000;
    string cmd;
    string product[lim];
    double price[lim];
    int i, quan[lim];
void title();
string Price(string product[], double price[]);
string Quantity(string product[], int quan[]);

void invoice(string product[], int quan[], double price[]);
// main
int main(){
    string cmd;
    string product[lim];
    double price[lim];
    int quan[lim];
    
    // the outlook
    input:
          title();
            
    system("pause");
    return 0;
}
    
   //function of title
void title(){
     input:     
     cout << "***************************************************************"
         << "\n*   Use the following commands to input data                  *" 
         << "\n*   /items     - only contains productid and quantity         *"
         << "\n*   /rawprices - only contains productid and price            *"
         << "\n*   /invoice   - print out a detailed invoice on the screen   *"
         << "\n*   /quit      - exit the program                             *"
         << "\n***************************************************************"; 
    
         cout << "\n <\\: ";
         cin >> cmd;
    
    //command for /rawprices
    if (cmd == "/rawprices"){  
        cout << Price(product, price) << endl;
    }
    
    //command for /items
    else if (cmd == "/items"){  
        cout << Quantity(product, quan) << endl;
    }
    
    //command for /invoice
    else if (cmd == "/invoice"){
     invoice(product, quan, price);
    }
     
    //command for /quit
    else if (cmd == "/quit"){
       
       exit (1);
      
    }
 
    //command valiation
    else {
       cout << "Invalid command" << endl;
       cout <<"Try again" << endl;
       Sleep (1000);
       system("cls");
       goto input;
    }
}


   //function of price
string Price(string product[], double price[]){
    int i;
    string id;
    cout << "\t Now you can enter data, to switch to different function"
          << "\n\t just enter any of the command."<< endl;
    cout << "\t Productid allows 2000 items"<< endl;
    
  for (int i = 0; i<lim; i++){
    
    cout << "product id: " ; cin >> product[i];
    if ( product[i] < "/" || product[i] > ":" && 
          product[i] < "A" || product[i] > "Z" &&
          product[i] < "a" || product[i] > "z"){      
     cout << "only supports alphanumeric format, try again: " << endl;
     cin >> product[i];
     }    
    else if (product[i] == "/invoice"){
     invoice(product, quan, price); 
    }
    else if (product[i] == "/items"){
    Quantity(product, quan);       
    }
    else if (product[i] == "/"){
    cout << "that is a command";
    exit (1);}
    else {
    cout << "$ "; cin >> price[i];
    }
  } 
return id;
}
    // function of quantity
string Quantity(string product[], int quan[]){
    int i;
    string id;
    
    cout << "\t Now you can enter data, to switch to different function"
          << "\n\t just enter any of the command."<< endl;
    cout << "\t Productid allows 2000 items"<< endl;    
    cout << "\t and Quanity limits at 1000."<< endl;
  for (int i = 0; i< lim; i++){
    cout << "product id: " ; cin >> product[i];
    
     if ( product[i] < "/" || product[i] > ":" && 
          product[i] < "A" || product[i] > "Z" &&
          product[i] < "a" || product[i] > "z"){      
     cout << "only supports alphanumeric format, try again: " << endl;
     cin >> product[i];
     }                 
    else if (product[i] == "/invoice"){
     invoice(product, quan, price); 
    }
    else if (product[i] == "/rawprices"){
    Price(product, price);       
    }
    else if (product[i] == "/"){
    cout << "that is a command";
    exit (1);
    }
    else {
    
    cout << "Number of items "; cin >> quan[i];
    
    if(quan[i] > 1000){
    cout << "1000 is the maximum number for items, try again" << endl;
    cin >> quan[i];
    }}   
  }  
return id;
}

    // function of invoice
void invoice(string product[], int quan[], double price[]){
     cout << "result: " << endl;  
     cout << "\t PHANTOM COMPANY INVOICE " << endl;
     cout << endl;
     cout << "PRODUCT ID" << setw(15) << "QUANTITY" << setw(18) << "PRICE ($)  "
          << setw(12) << "COST ($)" << endl;
     double TL;
     for (int i=0; i<10; i++){
     cout <<" " << product[i] << "\t\t"<< quan[i] << "\t  "
          << price[i] << "\t\t" << quan[i]*price[i] << endl;
          TL =  TL + quan[i]*price[i];
     }
     cout << "total = " << TL << endl;
     
     title();
}

what problem are you getting?? from the look on your code your having some unreferenced variables as well as redifinitions..an example is this..its unreferenced

double price[lim];

and also in your loops, i is redefined..and another thing..what is "input:"????

i have noticed that your loop goes to the limit till 1000...are you sure you want to keep inputing data up to 1000 times?? i think it would be wise to prompt the user for the amount of data they wish to enter then loop till that number..you need to also specify the fomulae according to what your question states

This article has been dead for over six months. Start a new discussion instead.