# Football management game in C++

Recently, I have been working on a College Football Manager game, in which you coach a team from the ground up. I have successfully made it to where you can win games, lose games, and change your team overall. Yet, I haven't worked out how to make a ranking system. I tried it with an Array, but got lost and had no idea what to do.

Keep in mind, not only does the player need to be ranked, but the other teams in the league. idon't know whether I would need to be simulating their seasons in the background(probably).

If possible, I would like it to be based off their overall. The overall is found under the team integer, for example.

int Kentucky 65;

Here is the project code, and I know, clunky, if you have any ideas on how to clean it up or shorten it, that would also be appreciated.

#include <iostream>
#include <string>
#include <cstdlib>
#include <stdlib.h>
#include <time.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{

string next;
string teams[10] = {"Clemson" , "Alabama" , "Georgia" , "Florida" , "Notre Dame" , "Auburn" , "Oklahoma" , "LSU" , "Miami FL" , "Oklahoma State"};
int select, ranking, teamoverall, wins, losses;
string team1, team2, userteam, nextgame;
int Alabama = 92;
int Clemson = 90;
int Georgia = 93;
int NotreDame = 88;
int MiamiFL = 80;
int Auburn = 86;
int Oklahoma = 85;
int LSU = 82;
int Florida  = 90;
int OklahomaST = 78;
int Kansas = 60;
int Kentucky = 60;
int TexasAM = 65;
float score, oppscore;
int final, oppfinal, random, random1;

team1 = "Arkanasas";
team2 = "Oklahoma State";

wins = 0;
losses = 0;

cout << "COLLEGE FOOTBALL COACH - 2020" << endl;
cout << "1 - Manage" << endl;
cout << "2 - Manual" << endl;
cout << "3 - About" << endl;
cin >> select;
if(select == 1){
goto TeamSelect;
}
if(select ==2){
goto Manual;
}
if(select == 3){
}

TeamSelect:
cout << string( 100, '\n' );
cout << "Choose a starting school to coach" << endl;
cout << "1- " << team1 << endl << "2- " << team2 << endl;
cin >> select;
if(select == 1){
userteam = "Arkansas";
ranking = 15;
nextgame = "Georgia";
teamoverall = 55;
}else{
userteam = "Oklahoma State";
ranking = 10;
nextgame = "Kansas";
teamoverall = 78;
}
goto Dynasty;

Dynasty:
cout << string( 100, '\n' );
cout << "Team - " << userteam << endl << endl;
cout << "Next Game - " << nextgame << " | Opponent Overall - ";
if(nextgame == "Georgia"){
cout << Georgia << endl << endl;
}else{
if(nextgame == "Kansas"){
cout << Kansas << endl << endl;
}else{
if(nextgame == "Kentucky"){
cout << Kentucky << endl << endl;
}else{
if(nextgame == "Auburn"){
cout << Auburn << endl << endl;
}else{
if(nextgame == "LSU"){
cout << LSU << endl << endl;
}else{
if(nextgame == "Texas A&M"){
cout << TexasAM << endl << endl;
}
}
}
}
}
}

cout << "Ranking - ";
if(ranking < 11){
cout << ranking << endl << endl;
}else{
cout << "UNRANKED" << endl << endl;
}
cout << "Record" << "(" << wins << " - " << losses << ")" << endl << endl;
cout << "Team Overall - " << teamoverall << endl << endl;
cout << "1- Play Next Game" << endl;
cout << "2- Recruting" << endl;
cout << "3- Rankings" << endl;
cin >> select;
if(select == 3){
goto rankings;
}else if(select ==1){
goto playgame;
}

playgame:
cout << string( 100, '\n' );
if(userteam == "Arkansas"){
if(nextgame == "Georgia"){
score = teamoverall * .5;
srand (time(NULL));
random = rand() % 5 + -20;
srand (time(NULL));
random1 = rand() % 20 + 1;
random = random + random1;

score = score + random;

oppscore = Georgia * .5;
srand (time(NULL));
random = rand() % 5 + -20;
srand (time(NULL));
random1 = rand() % 25 + 1;
random = random + random1;

oppscore = oppscore + random;

final = score;
oppfinal = oppscore;

if(final == oppfinal){
goto playgame;
}

if(final < 0){
final = 0;
}
if(oppfinal < 0){
oppfinal = 0;
}
if(final == 1){
final == 3;
}
if(final == 1){
final == 3;
}
if(oppfinal ==1){
oppfinal == 3;
}
if(score>oppscore){
wins = wins + 1;
teamoverall = teamoverall + 2;
}else{
losses = losses +1;
teamoverall = teamoverall - 2;
}

cout << "Arkansas scored " << final << " | Georgia scored " << oppfinal << endl << endl;
nextgame = "Kentucky";

cout << "Type 1 and press enter to continue..." << endl;
cin >> select;
goto Dynasty;

}else{
if(nextgame == "Kentucky"){
score = teamoverall * .5;
srand (time(NULL));
random = rand() % 5 + -20;
srand (time(NULL));
random1 = rand() % 20 + 1;
random = random + random1;

score = score + random;

oppscore = Kentucky * .5;
srand (time(NULL));
random = rand() % 10 + -25;
srand (time(NULL));
random1 = rand() % 25 + 1;
random = random + random1;

oppscore = oppscore + random;

final = score;
oppfinal = oppscore;

if(final == oppfinal){
goto playgame;
}

if(final < 0){
final = 0;
}
if(oppfinal < 0){
oppfinal = 0;
}
if(final == 1){
final == 3;
}
if(oppfinal ==1){
oppfinal ==3;
}

if(score>oppscore){
wins = wins + 1;
teamoverall = teamoverall + 2;
}else{
losses = losses +1;
teamoverall = teamoverall - 2;
}
cout << "Arkansas scored " << final << " | Kentucky scored " << oppfinal << endl << endl;
nextgame = "Auburn";
cout << "Type 1 and press enter to continue..." << endl;
cin >> select;
goto Dynasty;
}else{
if(nextgame == "Auburn"){
cout << string( 100, '\n' );
score = teamoverall * .5;
srand (time(NULL));
random = rand() % 5 + -25;
srand (time(NULL));
random1 = rand() % 20 + 1;
random = random + random1;

score = score + random;

oppscore = Auburn * .5;
srand (time(NULL));
random = rand() % 1 + -20;
srand (time(NULL));
random1 = rand() % 20 + 1;
random = random + random1;

oppscore = oppscore + random;

final = score;
oppfinal = oppscore;

if(final < 0){
final = 0;
}
if(oppfinal < 0){
oppfinal = 0;
}
if(final == 1){
final == 3;
}
if(oppfinal ==1){
oppfinal == 3;
}

if(final == oppfinal){
goto playgame;
}

if(score>oppscore){
wins = wins + 1;
teamoverall = teamoverall + 2;
}else{
losses = losses +1;
teamoverall = teamoverall - 2;
}

cout << "Arkansas scored " << final << " | Auburn scored " << oppfinal << endl << endl;
nextgame = "LSU";

cout << "Type 1 and press enter to continue..." << endl;
cin >> select;
goto Dynasty;
}else{
if(nextgame == "LSU"){
cout << string( 100, '\n' );
score = teamoverall * .5;
srand (time(NULL));
random = rand() % 5 + -15;
srand (time(NULL));
random1 = rand() % 25 + 1;
random = random + random1;

score = score + random;

oppscore = LSU * .5;
srand (time(NULL));
random = rand() % 1 + -20;
srand (time(NULL));
random1 = rand() % 25 + 1;
random = random + random1;

oppscore = oppscore + random;

final = score;
oppfinal = oppscore;

if(final < 0){
final = 0;
}
if(oppfinal < 0){
oppfinal = 0;
}
if(final == 1){
final == 3;
}
if(oppfinal ==1){
oppfinal ==3;
}

if(final == oppfinal){
goto playgame;
}

if(score>oppscore){
wins = wins + 1;
teamoverall = teamoverall + 2;
}else{
losses = losses +1;
teamoverall = teamoverall - 2;
}

cout << "Arkansas scored " << final << " | LSU scored " << oppfinal << endl << endl;
nextgame = "Texas A&M";

cout << "Type 1 and press enter to continue..." << endl;
cin >> select;
goto Dynasty;
}else{
if(nextgame == "Texas A&M"){
cout << string( 100, '\n' );
score = teamoverall * .5;
srand (time(NULL));
random = rand() % 10 + -20;
srand (time(NULL));
random1 = rand() % 30 + 1;
random = random + random1;

score = score + random;

oppscore = TexasAM * .5;
srand (time(NULL));
random = rand() % 5 + -15;
srand (time(NULL));
random1 = rand() % 20 + 1;
random = random + random1;

oppscore = oppscore + random;

final = score;
oppfinal = oppscore;

if(final < 0){
final = 0;
}
if(oppfinal < 0){
oppfinal = 0;
}
if(final == 1){
final == 3;
}
if(oppfinal ==1){
oppfinal = 3;
}

if(final == oppfinal){
goto playgame;
}

if(score>oppscore){
wins = wins + 1;
teamoverall = teamoverall + 2;
}else{
losses = losses +1;
teamoverall = teamoverall - 2;
}

cout << "Arkansas scored " << final << " | Texas A&M scored " << oppfinal << endl << endl;
nextgame = "Texas A&M";

cout << "Type 1 and press enter to continue..." << endl;
cin >> select;
goto Dynasty;
}
}
}
}
}
}

rankings:
cout << string( 100, '\n' );
cout << "1- " << teams[0] << endl;
cout << "2- " << teams[1] << endl;
cout << "3- " << teams[2] << endl;
cout << "4- " << teams[3] << endl;
cout << "5- " << teams[4] << endl;
cout << "6- " << teams[5] << endl;
cout << "7- " << teams[6] << endl;
cout << "8- " << teams[7] << endl;
cout << "9- " << teams[8] << endl;
cout << "10- " << teams[9] << endl;
cout << "Type 1 and press enter to go back..." << endl;
cin >> select;
goto Dynasty;
Manual:
cin >> select;
cin >> select;

}


• consider accepting an answer – Aryan Parekh Oct 10 at 11:10

Your code doesn't compile due to the invalid use of goto. Nevertheless, I have put in my thoughts.

# Dont using namespace std &  #include <bits/stdc++.h>

You should always try to avoid these two statements.

A very important part of writing clean code is that it is formatted properly. As it is currently, your code is extremely tough to read. Simply using a site like this one to format your code can help a lot

# What goes into main()?

I would highly suggest you to make use of functions to split the work. Your main() typically shouldn't perform all of this. You need to again, split the work into different functions which will make your code 100x more readable

An example of from your code can be

cout << "COLLEGE FOOTBALL COACH - 2020" << endl;
cout << "1 - Manage" << endl;
cout << "2 - Manual" << endl;
cout << "3 - About" << endl;


Why not assign this to a function called print_info() ? This way whenever you would want to print this, you wouldn't have to copy-past this but merely call print_info()

Your main function should be able to control the flow.

# goto?

I see goto statements everywhere in the code. It is now becoming increasingly difficult to read your code as I need to do Cntrl+f in my IDE to find the goto tag from the huge block of code. A much better alternative to it should be to use functions. Where each choice would call the respective function.

# Avoid the use of magic numbers

Magic numbers basically are

Unique values with unexplained meaning or multiple occurrences which could (preferably) be replaced with named constants

if(select == 1){...}


What is 1 to the reader? What if I could name the specific choices in a way that the functionality remains the same but the code is more readable?

## enums in C++

An enumeration is a user-defined type that consists of a set of named integral constants that are known as enumerators.

How will we implement the idea of enumerations here?

enum Choices{ manage = 1,manual,abort };


here when I set manage = 1, manual becomes 2, abort becomes 3... This way I can replace the line

if(select == 1){...}


Into

if(select == manage){...}


Now it is clear to the reader that if the user's selection is manage, do manage stuff.

# Use const or constexpr

You have a set of teams, std::string teams[10]. If you don't want to change this value during the run-time, it is a good practice to declare it const. This ensures that you will never change the value of teams. Hence, it will remain constant. Now even if you accidentally try to change teams. The compiler will throw an error and you will save yourself a lot of time.

# '\n' over std::endl

This might look like a very small, and unnecessary change. Both of them will achieve your purpose, but '\n' is much faster as std::endl; will flush the output buffer every time, which has performance issues.

'\n' vs std::endl in C++

# Object-Oriented-Programming

I think you yourself have figured out that your project is clunky. This is because the design of the program itself isn't good. You have randomly declared variables, and used goto to move around the huge block of code in the main() function.

There is a way that you can improve your code by a huge margin. And that is Object oriented programming.

You have a team, it has attributes like score, wins, losses, name, etc.

Why can't you have a class called Team that would have all these attributes and methods to manage the data properly? This way you would reduce a lot of the repetition in the code and make it faster.

class Team
{
public:
std::string name;
int wins;
int losses;
int teamoverall;

}


With this class, you would create an array of Teams which would all have these attributes. For example

Team new_team;
new_team.name = "Kansas";
new_team.wins = 5
// and the rest of the attributes


Note: I don't know the game of football nor am I American , I have just taken the key points from your code.

This would make it 100x easier to keep a track of what was going on.

Since you have multiple teams, you can create an array of objects this way.

Team all_teams[number_of_teams];


My example is a very basic class. Read this to know more about classes.

Since you directly have an array of teams, 1 loop through the array can get you the team with the max number of wins. It would look like this

Assuming the array of objects is initialized

std::string highest_scoring_team;
int max = 0;
for(auto const& team:array_of_teams)
{
if (team.max > max)
{
team.max = max;
highest_scoring_team = team.name
}
}


What's happening here? I have set the initial score to 0 (Hoping that is the lowest score possible). Now when go through the teams, if the score of any team is greater than max, max becomes that score. And at the same time i keep a record of the winning team. At the end highest_scoring_team will be the name of the team and max will be their score.

• Thank you, this helped loads. Though, could you provide thoughts on a ranking system, and how I could get that to work? – Troy Cox Oct 8 at 23:34
• @TroyCox I'm glad you found it useful, consider upvoting the answer if you do. About the ranking system . As I said I don't know a thing about football, so it is quite difficult for me to think of something that would be suitable for it – Aryan Parekh Oct 8 at 23:43
• I understand, but I just need like a key concept. Like, could that be done for a ray? Is it possible to move around the individual elements in a ray, like swap them back and forth? – Troy Cox Oct 8 at 23:45
• @TroyCox Can you do me a favor and briefly explain the ranking system part so I can edit my question to address this. Is the rank based on the scores of the teams? – Aryan Parekh Oct 8 at 23:47
• So the ranking system is based on team performance, so wins and losses pretty much. In real College Football, a committee interprets a team's performance, so it isn't just based off wins and losses, but also how they think they did. If we were to do that here, it would probably be really long, so just ranked off their wins would be great. – Troy Cox Oct 8 at 23:58

# Do not initialise srand over and over againg

srand (time(NULL)); should be called once. Details

# Use standard containers instead of raw arrays

std::array is excellent choice to store your data of known size. if you are using c++17 you don't even need to specify what or how many inside.

# You probably need a queue or stack maybe

if I comprehend correctly tons of gotos in your code you need std::queue to work with matchmaking and stuff.

# do not copy-paste thing when you can use cycle instead

cout << "1- " << teams[0] << endl;
cout << "2- " << teams[1] << endl;
cout << "3- " << teams[2] << endl;
cout << "4- " << teams[3] << endl;
cout << "5- " << teams[4] << endl;
cout << "6- " << teams[5] << endl;
cout << "7- " << teams[6] << endl;
cout << "8- " << teams[7] << endl;
cout << "9- " << teams[8] << endl;


could be printed as

const size_t teamCount = 8;
for (size_t i = 0; i < teamCount;++i) {
std::cout << (i+1) << "- " << teams[i] << "\n"; // note it's not endl
}
std::cout << std::endl; // push endl to flush data to IO-stream


It applies to other places where you render some menu for player. You can make some class out of it. And using queue also will require to use some loops as well

# Don't use reserved words

final is also cv-qualifier for virtual methods, so better name it something else.

• Great answer! Try using '\n' over std::endl as flushing the stream should only be done when absolutely required, '\n' does the same job much faster. – Aryan Parekh Oct 9 at 16:03