Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void add(vector<int>& data, vector<string>& names)
- {
- //some constants to make modifying the prompts a bit more simple.
- //note on the variable names: I use prefix notation, ergo
- //"agoals" stands for "Away goals", that is, goals made by the away team
- // prefix "h" is "home".
- const string NOTINT="Your input could not be converted to a sensible number! Make sure your input is a non-negative integer!";
- const string TOOLONG="Your input was too long! Please make sure that the name you input is, at maximum, 8 characters.";
- const string HNAMEPROMPT="Please input the name of the home team: ";
- const string ANAMEPROMPT="Please input the name of the away team: ";
- const string HGOALPROMPT= "Please input the number of goals made by the home team: ";
- const string AGOALPROMPT= "Please input the number of goals made by the away team: ";
- //temporary variable so I can do things to user input when needed
- string input="";
- //variable for storing the name of home team. Made nine characters long
- //because of the incoming while-loop
- string hname=" ";
- //same as above, for away team
- string aname=" ";
- //homegoals, initialization for incoming loops
- int hgoals=-1;
- //awaygoals, same as above
- int agoals=-1;
- //some slave variables so calculations don't have to be done a million times per
- //iteration of the function
- int helper1 = 0;
- int helper2 = 0;
- //this is why I initialized the names as I did.
- //I want the names to be at max 8 long, and the
- //program will keep pestering the user until it gets something
- //less or equal than eight characters
- while(hname.size()>8)
- {
- cout << HNAMEPROMPT;
- cin >> hname;
- if(hname.size>8)
- {
- //print error message if too long string
- cout TOOLONG; << endl;
- }
- }
- //same as above, only for away team's name
- while(aname.size()>8)
- {
- cout << ANAMEPROMPT;
- cin >> aname;
- if(aname.size>8)
- {
- cout TOOLONG; << endl;
- }
- }
- //parseint function used in this loop returns -1
- //if bullshit happens, so we'll keep pestering until
- //bullshit doesn't happen
- while(hgoals==-1)
- {
- cout << HGOALPROMPT;
- cin >> input;
- hgoals = parseInt(input);
- //if after attempting to make input into int it still remains
- //at error value, print error
- if(hgoals<0)
- {
- cout << NOTINT;
- }
- }
- //same as above while loop
- while(agoals==-1)
- {
- cout << AGOALPROMPT;
- cin >> input;
- agoals = parseInt(input);
- if(hgoals<0)
- {
- cout << NOTINT;
- }
- }
- //three simple, self-explanotary if-clauses
- if(hgoals>agoals)
- {
- cout << hname << " Won! Final score: " << hgoals << " - " << agoals;
- }
- if(hgoals<agoals)
- {
- cout << aname << " Won! Final score: " << hgoals << " - " << agoals;
- }
- if(hgoals==agoals)
- {
- cout << "The match was a draw! Final score: " << hgoals << " - " << hgoals;
- }
- //format() makes sure that input is in same format every time:
- //capital letter at the start, rest lowercase.
- //there are issues with it that I do not know how to solve
- format(hname);
- //exists(a,b) searches string vector
- //a for the string b, and returns the index
- //of b if found. If not, returns -1
- helper1=exists(names, hname);
- helper2=exists(names,aname);
- //if name is not found in "names", means it doesn't exist yet. Add the needed info
- //IMPORTANT NOTE ABOUT DATA FORMATTING!!!
- //names of teams are stored in one function
- //and data in another.
- //the order of the data, starting from index 0
- //is as follows
- //
- //0: overall points of team
- //1: overal wins
- //2: -||- losses
- //3: -||- draws
- //4: -||- goals scored
- //5: -||- goals suffered
- //
- //thus, any information of a team at
- //index i of "names" vector
- // can be accessed by multiplying i by 6
- //and adding tthe wanted number between 0 and 5
- if(helper1 == -1)
- {
- //helper1==-1, that means home team doesn't exist in the name list yet
- //add the dataset described above. Note that win scores you 3 points, draw 1 and loss 0
- if(hgoal>agoal)
- {
- data.push_back(3);
- data.push_back(1);
- data.push_back(0);
- data.push_back(0);
- data.push_back(hgoals);
- data.push_back(agoals);
- }
- if(hgoal<agoal);
- {
- data.push_back(0);
- data.push_back(0);
- data.push_back(1);
- data.push_back(0);
- data.push_back(hgoals);
- data.push_back(agoals)
- }
- if(hgoal==agoal);
- {
- data.push_back(0);
- data.push_back(0);
- data.push_back(1);
- data.push_back(0);
- data.push_back(hgoals);
- data.push_back(agoals)
- }
- }
- //same as above. Helper2 is away team, so info is fed accordingly
- if(helper2 == -1)
- {
- if(hgoal>agoal)
- {
- data.push_back(0);
- data.push_back(0);
- data.push_back(0);
- data.push_back(1);
- data.push_back(hgoals);
- data.push_back(agoals);
- }
- if(hgoal<agoal);
- {
- data.push_back(3);
- data.push_back(1);
- data.push_back(0);
- data.push_back(0);
- data.push_back(hgoals);
- data.push_back(agoals)
- }
- if(hgoal==agoal);
- {
- data.push_back(1);
- data.push_back(0);
- data.push_back(1);
- data.push_back(0);
- data.push_back(hgoals);
- data.push_back(agoals)
- }
- }
- if(helper1 != -1 && helper2 !=-1)
- {
- //both teams exist because helpers are both != -1
- //so info is fed in with the formula described at the start of this function
- data[helper1*6+4]=data[helper1*6+4]+hgoals;
- data[helper2*6+4]=data[helper2*6+4]+agoals;
- data[helper1*6+5]=data[helper1*6+5]+agoals;
- data[helper2*6+5]=data[helper2*6+5]+hgoals;
- if(hgoal>agoal)
- {
- data[helper1*6]=data[helper1*6]+3;
- data[helper1*6+1]=data[helper1*6+1]+1;
- data[helper2*+2]=data[helper2*+2]+1
- }
- if(hgoal<agoal)
- {
- data[helper2*6]=data[helper2*6]+3;
- data[helper2*6+1]=data[helper2*6+1]+1;
- data[helper1*+2]=data[helper1*+2]+1
- }
- if(hgoal==agoal);
- {
- data[helper1*6]=data[helper1*6]+1;
- data[helper2*6]=data[helper2*6]+1;
- data[helper1*6+3]=data[helper1*6+3]+1;
- data[helper2*6+3]=data[helper2*6+3]+1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement