title: storing all user inputs and display later
body: <p>I'm nearly finishing my practice program but I got stucked on storing user inputs in an unspecified size of an array..</p>
  
  <p>Please have a look at my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string&gt;
  #include &lt;ctype.h&gt;
  #include &lt;cstring&gt;
  
  using namespace std;
  
  int main()  {
  
      string items[9][3] = {{"A","BALOT","25.00"},
                              {"B","CANTON","20.00"},
                              {"C","NIDO","100.00"},
                              {"D","KETCHUP","50.00"},
                              {"E","MAGGI","15.00"},
                              {"F","ALASKA","60.00"},
                              {"G","VINEGAR","25.00"},
                              {"H","OIL","70.00"},
                              {"I","COKE","10.00"}};
  
      // PARA MAPRINT YUNG ARRAY.
      cout &lt;&lt; "MANG JUAN'S 10-DAHAN\n\n";
      for (int i = 0; i &lt; 9; i++) {
          for (int j = 0; j &lt; 3; j++)
              cout &lt;&lt; items[i][j] &lt;&lt; ( (j &lt; 2) ? "-" : "\t" ); 
  
          if (i &lt; 6) {
              cout &lt;&lt; "\t";
              i += 2;
          }
          else if (i != 8) { 
              cout &lt;&lt; "\n";
              i -= 6;
          }
      } // END OF ARRAY PRINTING
  
      char choice, addAnother;
      int ctr = 1, quantity = 0;
      string purchased;
      double price = 0, grandTotal = 0, total = 0;
  
      cout &lt;&lt; "\n\nWOULD YOU LIKE TO PURCHASE? Y/N\n\n";
      cin &gt;&gt; choice;
  
      if(choice == 'n' || choice == 'N') {
          cout &lt;&lt; "THANK YOU.";
      }
      else if(choice == 'y' || choice == 'Y') {
  
          string numPref;
          while (true) {
              if(ctr &gt; 11) {
                  cout &lt;&lt; "\n\nTHE SYSTEM EXCEEDED ITS LIMIT\n\n";
                  break;
              } else {
                  if(ctr == 1) numPref = "st";
                  else if(ctr == 2) numPref = "nd";
                  else if(ctr == 3) numPref = "rd";
                  else if(ctr &gt; 3) numPref = "th";
              }
  //rows:
              //for(int r = 0; r &lt; 9; r++) {
              cout &lt;&lt; "\n\nPLEASE ENTER " &lt;&lt; ctr &lt;&lt; numPref &lt;&lt; " ITEM:\t";
              cin &gt;&gt; purchased;
  
              char upp = purchased[0];
              upp = toupper(upp);
              purchased = upp;
  
              if(!cin) { 
                  cout &lt;&lt; "Letters only";
                  break;
              } else {
                  if(true) {
                      cout &lt;&lt; "HOW MANY? ";
                      cin &gt;&gt; quantity;
                      if(!cin) {
                          cout &lt;&lt; "Enter number only. ";
                          break;
                      } else {
                          cout &lt;&lt; "PRICE PER ITEM: ";
  
                      ///////// Look for the element and print the entire row /////////////
                          string *matchedRow;
                          const int length = 9;
                          for (int i = 0; i &lt; 9; i++) {
                              string *oneRow = items[i];
                              /**if (oneRow[0] != purchased) {
                                  cout &lt;&lt; "\n\nNO ITEM FOUND!\n\n";
                                  ctr--;
                              } else {
                                  matchedRow = oneRow;
                                  cout &lt;&lt; matchedRow[2];
                                  price = atof( matchedRow[2].c_str() );      
                                  total = price * quantity;
                                  grandTotal += total;    
                              } */
  
                                 if(oneRow[0] == purchased) {
                                      matchedRow = oneRow;
                                      cout &lt;&lt; matchedRow[2];
                                      price = atof( matchedRow[2].c_str() );                              
                                      total = price * quantity;
                                      grandTotal += total;
  
                                      if(oneRow[0] != purchased) {
                                          cout &lt;&lt; "NO MATCH FOUND!" &lt;&lt; endl;
                                          ctr--;
                                          break;
                                      }
  
                                  }
  
                          } // End of for-loop for *matchedrow
                          ////////////////////////////////////////////
                          cout &lt;&lt; "\n\nADD ANOTHER ITEM? Y/N " &lt;&lt; endl;
                          cin &gt;&gt; addAnother;
                          if(addAnother == 'y' || addAnother == 'Y') {
                              ctr++; 
                          } else if(addAnother == 'n' || addAnother == 'N') {
                              // print the receipt here
                              goto receipt;
                               //break; // replace break with goto later
                          } else {
                              cout &lt;&lt; "\n\nINVALID INPUT." &lt;&lt; endl;
                              break;
                          } // End of if and else for addANother
                      }
  
  
  
                      } // end of else - if (!cin) for quantity input check
                  } // end of char check
  
              //} // End of else for (!cin)     //spare bracket
  
          } // End of while-loop for numPref
          //} // end of rows for-loop 
      } // End of else if (choice)
  receipt:
      cout &lt;&lt; "YOUR PURCHASE:" &lt;&lt; endl;
      cout &lt;&lt; "NET TOTAL: " &lt;&lt; grandTotal &lt;&lt; endl;
      system("PAUSE");
      //return 0;
  
  }
  </code></pre>
  
  <p>I want to output the purchase summary like this sample run:</p>
  
  <pre><code>WOULD YOU LIKE TO PURCHASE? Y
  PLEASE ENTER 1st ITEM: A
  HOW MANY? 2
  PRICE PER ITEM: 25.00
  
  ADD ANOTHER? Y
  
  PLEASE ENTER 2nd ITEM: B
  HOW MANY? 1
  PRICE PER ITEM: 20.00
  
  ADD ANOTHER? N
  
  YOUR PURCHASE:
  // will display all the ordered item
  // sample output
  A     BALOT     50.00
  B     CANTON    20.00
  
  NET TOTAL: 70.00
  </code></pre>