[cpp] main

Viewer

  1. #pragma once 
  2. #include <iostream>
  3. #include "user.cpp"
  4. using namespace std;
  5.  
  6. int global_profit; //can also go inside main
  7. int global_launch;
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13.     MaxHeap mheap; //null right now 
  14.  
  15.     string input;
  16.     string instruction;
  17.     bool run = true;
  18.  
  19.     string user_id;
  20.     string num_votes;
  21.     string kUsers;
  22.     User tempUser;
  23.     Ndoe tempNode;
  24.  
  25.     //Bst tree instance of class
  26.     //Max heap instance of class object 
  27.  
  28.     while (run)
  29.     {
  30.         cout << "What would you like to do..." << endl; //do yuo want this prompt each time
  31.         cin >> input >> endl; //entire line in here
  32.         //instruction = input.substr(0, input.find(" ")); //shud shorten it
  33.         stringstream ss(input); //may need to switch to char array 
  34.         ss >> instruction;
  35.  
  36.         if(instruction == "register")
  37.         {
  38.             ss >> userid;
  39.             tempUser = User(userid);
  40.             tempNode = Node(tempUser);
  41.             if (BST.search(User) == false) 
  42.             {
  43.                 BST.insert(tempUser);
  44.             }
  45.             //trailing spaces, but can have spaces like fofr a first name and last name 
  46.         }
  47.         else if(instruction == "vote")
  48.         {
  49.             ss >> num_votes;
  50.             ss >> user_id;
  51.             tempUser = User(userid);
  52.             tempNode = Node(tempUser);
  53.  
  54.             if (num_votes % 2 == 0)
  55.             {
  56.                 global_launch = global_launch + (num_votes/2);
  57.                 global_profit = global_profit + (num_votes/2);
  58.             }
  59.             else //its odd
  60.             {
  61.                 global_launch = global_launch + (num_votes/2);
  62.                 global_profit = global_profit + (num_votes/2) + 1;
  63.                 //add that number of votes to the user specfied and we dont care where that money comes from
  64.             }   
  65.             //add that number of votes to the user specfied and we dont care where that money comes from
  66.  
  67.             BST.find()
  68.         }
  69.         else if(instruction == "scoreboard")
  70.         {   
  71.             ss >> kUsers;
  72.         }   
  73.         else if(instruction == "profit")
  74.         {
  75.             cout << "$" << global_profit << endl;
  76.         }
  77.         else {cout << "invalid input..." << endl;}
  78.         
  79.         // run the check to see if we launch, and iff we do extarct max 
  80.  
  81.  
  82.     }
  83. }

Editor

You can edit this paste and save as new:


File Description
  • main
  • Paste Code
  • 30 Nov-2021
  • 2.31 Kb
You can Share it: