Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- void menu(string username, string password) {
- double const SALES_TAX = .06875;
- string menu_setup, line, search, search1, key, price;
- string buy_statement, return_statement, cart_statement, price_initial, price_final;
- string divvy = "======================================\n";
- int opt, current_money, price_int;
- int n1,n4; // counters for reading lines
- int ben = 1; // ben runs everything
- cout << "CAMPUS_SHOP_V2\n" << divvy << "\n";
- menu_setup = "\n1.Buy\n2.Return\n3.List\n4.Cart\n5.Quit\n>";
- fstream inventory;
- fstream cart;
- fstream inv_source;
- int case_1_choice, case_2_choice, case_3_choice, case_4_choice;
- key = username + '.' + password;
- current_money = 200;
- while(ben == 1 && current_money > 0) {
- cout << menu_setup;
- cin >> opt;
- switch(opt) {
- case 1:
- n1 = 1;
- inventory.open("txt/inventory.txt");
- if (inventory.is_open()) {
- while(!inventory.eof()) {
- getline(inventory,line);
- cout << n1 << ": " << line << "\n";
- n1 += 1;
- }
- } else {
- cout << "Somehow the inventory isn't open";
- }
- inventory.close();
- cout << "\nBuy\n" << divvy << "[Enter item]\n> ";
- cin >> case_1_choice;
- inv_source.open("txt/inv_source.txt");
- switch(case_1_choice) {
- case 1:
- search = "Father Azzarto Bobblehead";
- search1 = ":";
- size_t pos;
- size_t pos1;
- while(inv_source.good()) {
- getline(inv_source,line); // get line from file
- //cout << '*' << line;
- pos=line.find(search); // search
- //cout << '$' << pos;
- pos1=line.find(search1);
- //cout << '#' << pos1 << endl; // for loop concenation
- for(pos ; pos < pos1; pos += 1) {
- //getline(inv_source, line);
- buy_statement += line[pos];
- }
- }
- price_initial = line.find('=');
- price_final = line.find('.');
- for(price_initial; price_initial < price_final; price_initial += 1) {
- price += line[price_initial];
- }
- price_int = stoi(price);
- // cout << "buy_statement = " <<buy_statement << endl; +++FLAG ALERT
- cart.open("txt/cart.txt");
- cart << key << "~" << buy_statement << endl;
- current_money -= price_int;
- cart.close();
- inv_source.close();
- break;
- case 2:
- search = "";
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- case 6:
- break;
- case 7:
- break;
- case 8:
- break;
- case 9:
- break;
- case 10:
- break;
- }
- /*
- cart.open("txt/cart.txt");
- if(cart.is_open()) {
- cout << "HERERERERERE";
- } else {
- cout << "cart file isn't open";
- }
- */
- //inv_source.close();
- //cart.close();
- break;
- case 2:
- cout << "\nReturn\n" << divvy << "[Enter item]\n>";
- cin >> case_2_choice;
- cart.close();
- break;
- case 3:
- n4 = 1;
- cout << "\nList\n" << divvy;
- inventory.open("txt/inventory.txt");
- if (inventory.is_open()) {
- while(!inventory.eof()) {
- getline(inventory,line);
- cout << n4 << ": " << line << "\n";
- n4 += 1;
- }
- } else {
- cout << "Somehow the inventory isn't open";
- }
- inventory.close();
- break;
- case 4:
- cout << "\nCart\n" << divvy;
- cart.open("txt/cart.txt");
- cart.close();
- break;
- case 5:
- cout << "\nQUIT\n" << divvy;// << "\n1.With items in cart\n2.Without any items\n>";
- ben -= 1;
- //cin >> case_4_choice;
- /*
- if(case_4_choice == 1) {
- ben -= 1;
- } else if(case_4_choice == 2) {
- cout << "Arrivederci";
- ben -= 1;
- }else{
- cout << "Hey, buddy what you doing my guy";
- }
- */
- break;
- default:
- cout << "Hey, hey buddy.";
- cout << "\n\n That's not an option\n\n\n\n\n\n\n\n";
- break;
- }
- // ben -= 1
- }
- }
- int main(){
- menu("usernam3","hash");
- return 0;
- }
- // https://stackoverflow.com/questions/12733888/regarding-c-include-another-class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement