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.

Recommended Answers

All 4 Replies

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();
}

How is it piping if you dont refer to the txt file?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.