Pass the horses to the displayMenu function. You will need a container of some sort. An array is a primitive container.
You will need to move types and functions that are required in multiple files into a header file.
For example, horse.hpp
#ifndef HORSE_HPP#define HORSE_HPP#include <string>struct Horse{ string name; int wins; int losses; double percentChanceOfWining;};const int MaxHorses = 5;struct Race{ Horse horses[MaxHorses];};void printHorseInfo(Horse horse);#endif
And menu.cpp
#include "stdafx.h"#include <iostream>#include "windows.h"#include "horses.h"using namespace std;//Call and draw the menuvoid displayMenu(Race race){ cout << "\nYou walk up to the betting stands, the horse's statistics are\ndisplayed on a screen" << endl; for(int i = 0 ; i < MaxHorses ; ++i) { printHorseStatistics(race.horses); }}
Then your "init_horses" could return a Race, which in turn returns the horses
// initiliaze the horses statsRace init_horses(){ // initliaze the horses horse charlie; horse cooldude; horse shiningFury; horse burningSoap; horse smellyPages; //Set the horses names charlie.name = "Charlie"; cooldude.name = "Cool Dude"; shiningFury.name = "Shining Fury"; burningSoap.name = "Burning Soap"; smellyPages.name = "Smelly Pages"; //set each horse's wins/losses to a number beetween 1 and 5 //to make it seem like the horse's have raced before and dont have 0 percent odds charlie.wins = rand() % 5 + 1; charlie.losses = rand() % 5 + 1; cooldude.wins = rand() % 5 + 1; cooldude.losses = rand() % 5 + 1; shiningFury.wins = rand() % 5 + 1; shiningFury.losses = rand() % 5 + 1; burningSoap.wins = rand() % 5 + 1; burningSoap.losses = rand() % 5 + 1; smellyPages.wins = rand() % 5 + 1; smellyPages.losses = rand() % 5 + 1; //set up their percent chance of winning charlie.percentChanceOfWining = calculate_horses_chances(charlie.wins, charlie.losses); cooldude.percentChanceOfWining = calculate_horses_chances(cooldude.wins, cooldude.losses); shiningFury.percentChanceOfWining = calculate_horses_chances(shiningFury.wins, shiningFury.losses); burningSoap.percentChanceOfWining = calculate_horses_chances(burningSoap.wins, burningSoap.losses);smellyPages.percentChanceOfWining = calculate_horses_chances(smellyPages.wins, smellyPages.losses); Race race = { charlie, cooldude, shiningFury, burningSoap, smellyPages }; return race;}
Any function that needs access to the horses can be passed the race instance, or just a single horse if that is all that is required. This is a simple example, leaving aside dynamic containers and pass by reference.
One final thing, the following calculation probably won't work for you:
(wins / losses) * 100;
C++ will use integer division unless one of the types is a float or double. This means that the result is the same as division with the remainder discarded. You can change the types of the variables involved, use a cast or simply rearrange the code such that the constant 100.0 is used as the center of the operation:
(wins * 100.0 / losses);
Now the integers are "upgraded" or "promoted" to doubles and you won't have the same problem of the remainder being discarded.
You probably should include a special check in the case losses is 0.