Advertisement
okelikai

campusShopMenu

Oct 20th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. void menu(string username, string password) {
  6.     double const SALES_TAX = .06875;
  7.     string menu_setup, line, search, search1, key, price;
  8.     string buy_statement, return_statement, cart_statement, price_initial, price_final;
  9.     string divvy = "======================================\n";
  10.     int opt, current_money, price_int;
  11.     int n1,n4;  // counters for reading lines
  12.     int ben = 1; // ben runs everything
  13.    
  14.     cout << "CAMPUS_SHOP_V2\n" << divvy << "\n";
  15.    
  16.     menu_setup = "\n1.Buy\n2.Return\n3.List\n4.Cart\n5.Quit\n>";
  17.    
  18.     fstream inventory;
  19.     fstream cart;
  20.     fstream inv_source;
  21.    
  22.     int case_1_choice, case_2_choice, case_3_choice, case_4_choice;
  23.     key = username + '.' + password;
  24.    
  25.     current_money = 200;
  26.    
  27.     while(ben == 1 && current_money > 0) {
  28.         cout << menu_setup;
  29.         cin >> opt;
  30.        
  31.         switch(opt) {
  32.             case 1:
  33.                 n1 = 1;
  34.                 inventory.open("txt/inventory.txt");
  35.                 if (inventory.is_open()) {
  36.                     while(!inventory.eof()) {
  37.                         getline(inventory,line);
  38.                         cout << n1 << ": " << line << "\n";
  39.                         n1 += 1;
  40.                     }
  41.                 } else {
  42.                     cout << "Somehow the inventory isn't open";
  43.                 }
  44.                 inventory.close();
  45.                
  46.                
  47.                 cout << "\nBuy\n" << divvy << "[Enter item]\n> ";
  48.                 cin >> case_1_choice;
  49.                 inv_source.open("txt/inv_source.txt");
  50.                 switch(case_1_choice) {
  51.                     case 1:
  52.                         search = "Father Azzarto Bobblehead";
  53.                         search1 = ":";
  54.                        
  55.                         size_t pos;
  56.                         size_t pos1;
  57.                         while(inv_source.good()) {
  58.                             getline(inv_source,line); // get line from file
  59.                             //cout << '*' << line;
  60.                             pos=line.find(search); // search
  61.                             //cout << '$' << pos;
  62.                             pos1=line.find(search1);
  63.                             //cout << '#' << pos1 << endl;   // for loop concenation
  64.                            
  65.                             for(pos ; pos < pos1; pos += 1) {
  66.                                     //getline(inv_source, line);
  67.                                     buy_statement += line[pos];
  68.                                 }
  69.                             }
  70.                            
  71.                             price_initial = line.find('=');
  72.                             price_final = line.find('.');
  73.                             for(price_initial; price_initial < price_final; price_initial += 1) {
  74.                                 price += line[price_initial];
  75.                             }
  76.                            
  77.                         price_int = stoi(price);    
  78.                         // cout << "buy_statement = " <<buy_statement << endl; +++FLAG ALERT
  79.                         cart.open("txt/cart.txt");
  80.                             cart << key << "~" << buy_statement << endl;
  81.                             current_money -= price_int;
  82.                         cart.close();
  83.                         inv_source.close();
  84.                         break;
  85.                     case 2:
  86.                         search = "";
  87.                         break;
  88.                     case 3:
  89.                         break;
  90.                     case 4:
  91.                         break;
  92.                     case 5:
  93.                         break;
  94.                     case 6:
  95.                         break;
  96.                     case 7:
  97.                         break;
  98.                     case 8:
  99.                         break;
  100.                     case 9:
  101.                         break;
  102.                     case 10:
  103.                         break;
  104.                 }
  105.                 /*
  106.                 cart.open("txt/cart.txt");
  107.                 if(cart.is_open()) {
  108.                     cout << "HERERERERERE";
  109.                 } else {
  110.                     cout << "cart file isn't open";
  111.                 }
  112.                 */
  113.                 //inv_source.close();
  114.                 //cart.close();
  115.                 break;
  116.             case 2:
  117.                 cout << "\nReturn\n" << divvy << "[Enter item]\n>";
  118.                 cin >> case_2_choice;
  119.                
  120.                
  121.                 cart.close();
  122.                 break;
  123.                
  124.             case 3:
  125.                 n4 = 1;
  126.                 cout << "\nList\n" << divvy;
  127.                 inventory.open("txt/inventory.txt");
  128.                 if (inventory.is_open()) {
  129.                     while(!inventory.eof()) {
  130.                         getline(inventory,line);
  131.                         cout << n4 << ": " << line << "\n";
  132.                         n4 += 1;
  133.                     }
  134.                 } else {
  135.                     cout << "Somehow the inventory isn't open";
  136.                 }
  137.                 inventory.close();
  138.                 break;
  139.                
  140.             case 4:
  141.                 cout << "\nCart\n" << divvy;
  142.                 cart.open("txt/cart.txt");
  143.                
  144.                
  145.                 cart.close();
  146.                 break;
  147.                
  148.             case 5:
  149.                 cout << "\nQUIT\n" << divvy;// << "\n1.With items in cart\n2.Without any items\n>";
  150.                 ben -= 1;
  151.                 //cin >> case_4_choice;
  152.                 /*
  153.                 if(case_4_choice == 1) {
  154.                    
  155.                     ben -= 1;
  156.                 } else if(case_4_choice == 2) {
  157.                     cout << "Arrivederci";
  158.                     ben -= 1;
  159.                    
  160.                 }else{
  161.                     cout << "Hey, buddy what you doing my guy";
  162.                 }
  163.                 */
  164.                 break;
  165.             default:
  166.                 cout << "Hey, hey buddy.";
  167.                 cout << "\n\n That's not an option\n\n\n\n\n\n\n\n";
  168.                 break;
  169.         }
  170.        
  171.        
  172.         // ben -= 1
  173.     }
  174.    
  175. }
  176.  
  177. int main(){
  178.     menu("usernam3","hash");
  179.     return 0;
  180. }
  181.  
  182. // https://stackoverflow.com/questions/12733888/regarding-c-include-another-class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement