Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Feb 24th, 2012  |  syntax: C++  |  size: 2.02 KB  |  hits: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <utility>
  5. // !! You had no use for iomanip
  6.  
  7. using namespace std;
  8.  
  9. struct ITM_TYPE
  10. {
  11.         std::vector< std::pair< std::string, float > > items;
  12.         int seatN;
  13. };
  14.  
  15. // !! You had an unused function here
  16.  
  17. int main()
  18. {
  19.         // !! These had no business being global variables
  20.         int N_ITEMS;
  21.         int N_SEATS;
  22.         int seat;
  23.         int tItems = 0;
  24.  
  25.         cout << "Enter the number of seats: ";
  26.         cin >> N_SEATS; //retrive number of seats
  27.  
  28.         // !! This is not needed if you iterate starting at 0
  29.         N_SEATS += 1;
  30.  
  31.         // !! You can not dynamically create arrays like you did. Do it like below
  32.         // !! Also you used N_ITEMS incorrectly as opposed to N_SEATS
  33.         // !! This was also out of scope inside the for (the second for did not know it existed)
  34.         // !! Plus it was being re-created on every iteration
  35.         std::vector< ITM_TYPE > items;
  36.  
  37.         for( seat = 1; seat < N_SEATS; seat++ ) // loop for each seat
  38.         {
  39.                 cout << "Enter number of items for seat" << seat <<": ";
  40.                 cin >> N_ITEMS; //get number of items for seat
  41.                 tItems += N_ITEMS;
  42.  
  43.                 string name;
  44.                 float price;
  45.  
  46.                 ITM_TYPE nItem;
  47.                 nItem.seatN = seat;
  48.  
  49.                 // !! If you are initializing an iterator variable, then incrementing on each
  50.                 // !! loop, then just use a for instead of a while. Thats why it exists
  51.                 for( int i = 0; i < N_ITEMS; i++ )
  52.                 {
  53.                         cout << "Input item name: ";
  54.                         cin >> name;
  55.  
  56.                         cout << "item[" << i << "].name SET" << endl;
  57.                         cout << "Input item price: ";
  58.                         cin >> price;
  59.  
  60.                         cout << "item[" << i << "].price SET" << endl;
  61.  
  62.                         nItem.items.push_back( std::pair< std::string, float >( name, price ) );
  63.                 }
  64.  
  65.                 items.push_back( nItem );
  66.         }
  67.  
  68.         for( int i = 0; i < items.size( ); i++ )
  69.         {
  70.                 std::cout << "Seat #" << i + 1 << std::endl;
  71.  
  72.                 for( int j = 0; j < items[ i ].items.size( ); j++ )
  73.                         std::cout << "Name: " << items[ i ].items[ j ].first << "\nPrice: " << items[ i ].items[ j ].second << std::endl;
  74.         }
  75.  
  76.         system( "pause" );
  77.  
  78.         // !! You did not indicate a successful end of program
  79.         return 0;
  80. }