Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.98 KB | None | 0 0
  1. void add(vector<int>& data, vector<string>& names)
  2. {
  3.     //some constants to make modifying the prompts a bit more simple.
  4.     //note on the variable names: I use prefix notation, ergo
  5.     //"agoals" stands for "Away goals", that is, goals made by the away team
  6.     // prefix "h" is "home".
  7.     const string NOTINT="Your input could not be converted to a sensible number! Make sure your input is a non-negative integer!";
  8.     const string TOOLONG="Your input was too long! Please make sure that the name you input is, at maximum, 8 characters.";
  9.     const string HNAMEPROMPT="Please input the name of the home team: ";
  10.     const string ANAMEPROMPT="Please input the name of the away team: ";
  11.     const string HGOALPROMPT= "Please input the number of goals made by the home team: ";
  12.     const string AGOALPROMPT= "Please input the number of goals made by the away team: ";
  13.     //temporary variable so I can do things to user input when needed
  14.     string input="";
  15.     //variable for storing the name of home team. Made nine characters long
  16.     //because of the incoming while-loop
  17.     string hname="         ";
  18.     //same as above, for away team
  19.     string aname="         ";
  20.     //homegoals, initialization for incoming loops
  21.     int hgoals=-1;
  22.     //awaygoals, same as above
  23.     int agoals=-1;
  24.     //some slave variables so calculations don't have to be done a million times per
  25.     //iteration of the function
  26.     int helper1 = 0;
  27.     int helper2 = 0;
  28.     //this is why I initialized the names as I did.
  29.     //I want the names to be at max 8 long, and the
  30.     //program will keep pestering the user until it gets something
  31.     //less or equal than eight characters
  32.     while(hname.size()>8)
  33.     {
  34.         cout << HNAMEPROMPT;
  35.         cin >> hname;
  36.         if(hname.size>8)
  37.         {
  38.             //print error message if too long string
  39.             cout TOOLONG; << endl;
  40.         }
  41.     }
  42.     //same as above, only for away team's name
  43.     while(aname.size()>8)
  44.     {
  45.         cout << ANAMEPROMPT;
  46.         cin >> aname;
  47.         if(aname.size>8)
  48.         {
  49.             cout TOOLONG; << endl;
  50.         }
  51.     }
  52.     //parseint function used in this loop returns -1
  53.     //if bullshit happens, so we'll keep pestering until
  54.     //bullshit doesn't happen
  55.     while(hgoals==-1)
  56.     {
  57.         cout << HGOALPROMPT;
  58.         cin >> input;
  59.         hgoals = parseInt(input);
  60.         //if after attempting to make input into int it still remains
  61.         //at error value, print error
  62.         if(hgoals<0)
  63.         {
  64.             cout << NOTINT;
  65.         }
  66.     }
  67.     //same as above while loop
  68.     while(agoals==-1)
  69.     {
  70.         cout << AGOALPROMPT;
  71.         cin >> input;
  72.         agoals = parseInt(input);
  73.         if(hgoals<0)
  74.         {
  75.             cout << NOTINT;
  76.         }
  77.     }
  78.     //three simple, self-explanotary if-clauses
  79.     if(hgoals>agoals)
  80.     {
  81.         cout << hname << " Won! Final score: " << hgoals << " - " << agoals;
  82.     }
  83.     if(hgoals<agoals)
  84.     {
  85.         cout << aname << " Won! Final score: " << hgoals << " - " << agoals;
  86.     }
  87.     if(hgoals==agoals)
  88.     {
  89.         cout << "The match was a draw! Final score: " << hgoals << " - " << hgoals;
  90.     }
  91.     //format() makes sure that input is in same format every time:
  92.     //capital letter at the start, rest lowercase.
  93.     //there are issues with it that I do not know how to solve
  94.     format(hname);
  95.     //exists(a,b) searches string vector
  96.     //a for the string b, and returns the index
  97.     //of b if found. If not, returns -1
  98.     helper1=exists(names, hname);
  99.     helper2=exists(names,aname);
  100.     //if name is not found in "names", means it doesn't exist yet. Add the needed info
  101.     //IMPORTANT NOTE ABOUT DATA FORMATTING!!!
  102.     //names of teams are stored in one function
  103.     //and data in another.
  104.     //the order of the data, starting from index 0
  105.     //is as follows
  106.     //
  107.     //0: overall points of team
  108.     //1: overal wins
  109.     //2: -||- losses
  110.     //3: -||- draws
  111.     //4: -||- goals scored
  112.     //5: -||- goals suffered
  113.     //
  114.     //thus, any information of a team at
  115.     //index i of "names" vector
  116.     // can be accessed by multiplying i by 6
  117.     //and adding tthe wanted number between 0 and 5
  118.     if(helper1 == -1)
  119.     {
  120.         //helper1==-1, that means home team doesn't exist in the name list yet
  121.         //add the dataset described above. Note that win scores you 3 points, draw 1 and loss 0
  122.         if(hgoal>agoal)
  123.         {
  124.             data.push_back(3);
  125.             data.push_back(1);
  126.             data.push_back(0);
  127.             data.push_back(0);
  128.             data.push_back(hgoals);
  129.             data.push_back(agoals);
  130.         }
  131.         if(hgoal<agoal);
  132.         {
  133.             data.push_back(0);
  134.             data.push_back(0);
  135.             data.push_back(1);
  136.             data.push_back(0);
  137.             data.push_back(hgoals);
  138.             data.push_back(agoals)
  139.         }
  140.         if(hgoal==agoal);
  141.         {
  142.             data.push_back(0);
  143.             data.push_back(0);
  144.             data.push_back(1);
  145.             data.push_back(0);
  146.             data.push_back(hgoals);
  147.             data.push_back(agoals)
  148.         }
  149.     }
  150.     //same as above. Helper2 is away team, so info is fed accordingly
  151.     if(helper2 == -1)
  152.     {
  153.         if(hgoal>agoal)
  154.         {
  155.             data.push_back(0);
  156.             data.push_back(0);
  157.             data.push_back(0);
  158.             data.push_back(1);
  159.             data.push_back(hgoals);
  160.             data.push_back(agoals);
  161.         }
  162.         if(hgoal<agoal);
  163.         {
  164.             data.push_back(3);
  165.             data.push_back(1);
  166.             data.push_back(0);
  167.             data.push_back(0);
  168.             data.push_back(hgoals);
  169.             data.push_back(agoals)
  170.         }
  171.         if(hgoal==agoal);
  172.         {
  173.             data.push_back(1);
  174.             data.push_back(0);
  175.             data.push_back(1);
  176.             data.push_back(0);
  177.             data.push_back(hgoals);
  178.             data.push_back(agoals)
  179.         }
  180.     }
  181.     if(helper1 != -1 && helper2 !=-1)
  182.     {
  183.         //both teams exist because helpers are both != -1
  184.         //so info is fed in with the formula described at the start of this function
  185.         data[helper1*6+4]=data[helper1*6+4]+hgoals;
  186.         data[helper2*6+4]=data[helper2*6+4]+agoals;
  187.         data[helper1*6+5]=data[helper1*6+5]+agoals;
  188.         data[helper2*6+5]=data[helper2*6+5]+hgoals;
  189.         if(hgoal>agoal)
  190.         {
  191.             data[helper1*6]=data[helper1*6]+3;
  192.             data[helper1*6+1]=data[helper1*6+1]+1;
  193.             data[helper2*+2]=data[helper2*+2]+1
  194.         }
  195.         if(hgoal<agoal)
  196.         {
  197.             data[helper2*6]=data[helper2*6]+3;
  198.             data[helper2*6+1]=data[helper2*6+1]+1;
  199.             data[helper1*+2]=data[helper1*+2]+1
  200.         }
  201.         if(hgoal==agoal);
  202.         {
  203.             data[helper1*6]=data[helper1*6]+1;
  204.             data[helper2*6]=data[helper2*6]+1;
  205.             data[helper1*6+3]=data[helper1*6+3]+1;
  206.             data[helper2*6+3]=data[helper2*6+3]+1;
  207.         }
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement