So I am trying to figure out a way to add up the total scores for each team as well determine who goes to the quarter-final, semis and finals. So far I've managed to come up with a way to randomize the team, randomize the amount of goals scored by the team whether it was by penalty or direct winner. I need some suggestion on how I can create an elimination which is able to take the random scores generated and then allow the program to then send those teams to other rounds(An elimination method just like the World Cup) and lastly is still able to add the total number of goals scored by each team. I'm a beginner so I was thinking of using a struct for it but not sure how exactly that would work or even how to write the code to do it even if I could.
#include <iostream>
#include <string>
#include <ctime>
#include <random>
#include <algorithm>
#include <thread>
#include <chrono>
#include <cmath>
#include <fstream>
#include <cstdlib>
using namespace std;
struct Values{
int win;
int loss;
int penalty;
int randomNumber;
int randomDigit;
}myNum;
void draw(string teams[],size_t num_teams ) ;
int main()
{
using namespace std;
cout << "Welcome to the FIFA World Cup draw\n"
<< "\nThe draw will include the following teams:\n\n" ;
const size_t NTEAMS = 16 ;
string teams[NTEAMS] =
{
"Argentina",
"Portugal",
"England",
"Germany",
"United States",
"France",
"Spain",
"Japan",
"Canada",
"Mexico",
"Poland",
"South Korea",
"Uruguay",
"Wales",
"Switzerland",
"Croatia"
};
for( const string& team_name : teams ) cout << '\t' << team_name << '\n' ;
cout << "\nThere are no rules in regards to which team can play who.\n"
<< "Anyone can draw anyone!\n\n"
<< "To start the draw, please press s and enter!\n"
<< "Good luck to all teams!\n\n";
char start ;
std::cin >> start;
if ( (start == 's') || (start == 'S') ) draw( teams, NTEAMS ) ;
else
{
std::cout << "\nInvalid entry! the program will now close!\n"
<< "Open again and only press s to start the draw!\n" ;
}
}
void draw( std::string teams[], std::size_t num_teams )
{
// random number engine, seeded with the current time
std::mt19937 rng( std::time(nullptr) ) ;
// shuffle the teams in the array like we would shuffle a pack of cards
std::shuffle( teams, teams+num_teams, rng ) ;
// print out the pairings
for( std::size_t i = 0 ; i < num_teams ; i += 2 )
{
std::this_thread::sleep_for( std::chrono::seconds(1) ) ;
std::cout << "\n\t" << teams[i] << " vs. " << teams[i+1] << '\n' ;
srand((unsigned) time(0));
int randomNumber;
int randomDigit;
string win;
string penalty;
string loss;
for(int i=0; i<1; i++){
randomNumber=(rand() % 10);
randomDigit=(rand() % 10);
win = "Direct Win";
penalty = "By Penalty";
loss = "Direct Loss";
std::cout <<"Round scores: " <<randomNumber << " vs. " << randomDigit << '\n';
if (randomNumber > randomDigit ){
std::cout << win;
} else if ( randomNumber <= randomDigit ) {
std::cout << penalty;
}
}
}
}