Question: C++ I need to add a function for the following code which determines and displays the winner of the race. //Program Description: Horse Racing Game

C++

I need to add a function for the following code which determines and displays the winner of the race.

//Program Description: Horse Racing Game //Date: April 12, 2017

#include #include//for rand() code #include//For time() code #include//For sleep() code

using namespace std;

int speed(int horseSpeed) { horseSpeed = horseSpeed + rand() % 10 + 1; //This code will be randomly generated between 1 and 10. return horseSpeed; }

void horsePosition(int a) { int i; a = a / 10; //Distance horse travel on screen. //Larger values slow the movement down.95 for (i = 0; i <= a; i++) { //loop will place horse on screen in proper position. if (i == a) cout << "~n-n^" << endl; else cout << " "; //will draw space until the current position is reached. } }

int main() { int a, b, c, d, e, f, g, h; a = b = c = d = e = f = g = h = 0; //Set all horses to same tarting position int race, winner = 0;

srand(time(NULL)); //Null previous random number. //This ensures the program will generate new random numbers.

for (race = 0; race <= 50; race++)//Race continues for 50 iterations { a = speed(a);//Call function to get speed for each horse returns a cumulative value that contines to build into the end of the race. b = speed(b); c = speed(c); d = speed(d); e = speed(e); f = speed(f); g = speed(g); h = speed(h);

cout << "Speedy: "; horsePosition(a);//Call function for the horse position cout << "Rider: "; horsePosition(b); cout << "Blaze: "; horsePosition(c); cout << "Jolt: "; horsePosition(d); cout << "Knight: "; horsePosition(e); cout << "Boulder: "; horsePosition(f); cout << "Torrent: "; horsePosition(g); cout << "Wave: "; horsePosition(h);

cout << " Final Count Values" << endl; cout << "Shadow: " << a << endl; cout << "Luster: " << b << endl; cout << "Blaze: " << c << endl; cout << "Jolt: " << d << endl; cout << "Knight: " << e << endl; cout << "Boulder: " << f << endl; cout << "Torrent: " << g << endl; cout << "Wave: " << h << endl;

Sleep(25);//Slows down the horses. CHange the value to add drama. if (race < 50) system("CLS"); //Keep screen clear until end of race. }

system("pause"); return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!