Kain
01-11-04, 12:16 PM
I need to make a golf game for my C++ class. It is due on Tuesday. This is what the game needs to do: In this game the user will play either nine or eighteen holes of golf. The computer should choose random numbers for appropriate length and par for the hole. The player should choose from a selection of, say, three woods and five irons, all of which will hit the ball a random distance within a given range. The computer should then tell the player his new distance to the hold and allow a new club to be selected. The process should be repeated until the player completes the hole. The computer, of course, should keep track of the number of strokes. Considerations: advising the player when he/she is "on the green," establishing a range for successful completion of a putt, what to do when a player overshoots the hole, and adding random slices, hooks, and fairway hazards. Report results back to the user at the end. The program that I have written so far doesn't really work. I still need to work out how I will calculated the distance and how I will actually make the game work. Can someone please help?
This is what I have so far:
#include <iostream.h>
#include <lvprandom.h>
void Hole()
{
int hole;
cout << "Would you like to play a 9 or 18-hole game? ";
cin >> hole;
if (hole == 9)
{
int hole1 = ((50+lvprandom(200));
int hole2 = ((50+lvprandom(320))-hole1);
int hole3 = ((50+lvprandom(540))-hole2);
int hole4 = ((50+lvprandom(680))-hole3);
int hole5 = ((50+lvprandom(800))-hole4);
int hole6 = ((50+lvprandom(1200))-hole5);
int hole7 = ((50+lvprandom(1400))-hole6);
int hole8 = ((50+lvprandom(1600))-hole7);
int hole9 = ((50+lvprandom(1800))-hole8);
}
else if (hole == 18)
{
int hole1 = ((50+lvprandom(200));
int hole2 = ((50+lvprandom(400))-hole1);
int hole3 = ((50+lvprandom(600))-hole2);
int hole4 = ((50+lvprandom(800))-hole3);
int hole5 = ((50+lvprandom(1000))-hole4);
int hole6 = ((50+lvprandom(1200))-hole5);
int hole7 = ((50+lvprandom(1400))-hole6);
int hole8 = ((50+lvprandom(1600))-hole7);
int hole9 = ((50+lvprandom(1800))-hole8);
int hole10 = ((50+lvprandom(2000))-hole9);
int hole11 = ((50+lvprandom(2200))-hole10);
int hole12 = ((50+lvprandom(2400))-hole11);
int hole13 = ((50+lvprandom(2600))-hole12);
int hole14 = ((50+lvprandom(2800))-hole13);
int hole15 = ((50+lvprandom(3000))-hole14);
int hole16 = ((50+lvprandom(3200))-hole15);
int hole17 = ((50+lvprandom(3400))-hole16);
int hole18 = ((50+lvprandom(3600))-hole17);
}
else
{
while (hole != 9 || 18)
{
cout << "Please enter either 9 or 18: ";
cin >> hole;
}
}
}
void Instructions()
{
cout << "These are the Instructions." << endl;
cout << endl;
Hole();
}
void Clubs(int club)
{
int distance, club;
if club=1
distance=20+lvprandom(40);
else if club=2
distance=40+lvprandom(60);
else if club=3
distance=60+lvprandom(80);
else if club=4
distance=80+lvprandom(100);
else if club=5
distance=100+lvprandom(120);
else if club=6
distance=200+lvprandom(50);
else
cout << "Please enter a club number from 1 to 6: ";
cin >> club;
{
void Introduction()
{
char answer;
cout << "Welcome to Golf 2004!" << endl;
cout << endl;
cout << "Would you like to read the Instructions? y/n: ";
cin >> answer;
if (answer == 'y')
Instructions();
else
{
while (answer != 'y' || 'n")
cout << "Please enter either y or n: ";
cin >> answer;
}
void Distance()
{
int hole, counter, distance;
cout << "Would you like to play a 9 or 18-hole game? ";
cin >> hole;
for (counter=1, counter<hole, counter++)
{
distance =
cout << "Distance to hole " << counter << " is " << distance << " yards."
int main()
{
randomize();
Introduction();
return(0);
}
This is what I have so far:
#include <iostream.h>
#include <lvprandom.h>
void Hole()
{
int hole;
cout << "Would you like to play a 9 or 18-hole game? ";
cin >> hole;
if (hole == 9)
{
int hole1 = ((50+lvprandom(200));
int hole2 = ((50+lvprandom(320))-hole1);
int hole3 = ((50+lvprandom(540))-hole2);
int hole4 = ((50+lvprandom(680))-hole3);
int hole5 = ((50+lvprandom(800))-hole4);
int hole6 = ((50+lvprandom(1200))-hole5);
int hole7 = ((50+lvprandom(1400))-hole6);
int hole8 = ((50+lvprandom(1600))-hole7);
int hole9 = ((50+lvprandom(1800))-hole8);
}
else if (hole == 18)
{
int hole1 = ((50+lvprandom(200));
int hole2 = ((50+lvprandom(400))-hole1);
int hole3 = ((50+lvprandom(600))-hole2);
int hole4 = ((50+lvprandom(800))-hole3);
int hole5 = ((50+lvprandom(1000))-hole4);
int hole6 = ((50+lvprandom(1200))-hole5);
int hole7 = ((50+lvprandom(1400))-hole6);
int hole8 = ((50+lvprandom(1600))-hole7);
int hole9 = ((50+lvprandom(1800))-hole8);
int hole10 = ((50+lvprandom(2000))-hole9);
int hole11 = ((50+lvprandom(2200))-hole10);
int hole12 = ((50+lvprandom(2400))-hole11);
int hole13 = ((50+lvprandom(2600))-hole12);
int hole14 = ((50+lvprandom(2800))-hole13);
int hole15 = ((50+lvprandom(3000))-hole14);
int hole16 = ((50+lvprandom(3200))-hole15);
int hole17 = ((50+lvprandom(3400))-hole16);
int hole18 = ((50+lvprandom(3600))-hole17);
}
else
{
while (hole != 9 || 18)
{
cout << "Please enter either 9 or 18: ";
cin >> hole;
}
}
}
void Instructions()
{
cout << "These are the Instructions." << endl;
cout << endl;
Hole();
}
void Clubs(int club)
{
int distance, club;
if club=1
distance=20+lvprandom(40);
else if club=2
distance=40+lvprandom(60);
else if club=3
distance=60+lvprandom(80);
else if club=4
distance=80+lvprandom(100);
else if club=5
distance=100+lvprandom(120);
else if club=6
distance=200+lvprandom(50);
else
cout << "Please enter a club number from 1 to 6: ";
cin >> club;
{
void Introduction()
{
char answer;
cout << "Welcome to Golf 2004!" << endl;
cout << endl;
cout << "Would you like to read the Instructions? y/n: ";
cin >> answer;
if (answer == 'y')
Instructions();
else
{
while (answer != 'y' || 'n")
cout << "Please enter either y or n: ";
cin >> answer;
}
void Distance()
{
int hole, counter, distance;
cout << "Would you like to play a 9 or 18-hole game? ";
cin >> hole;
for (counter=1, counter<hole, counter++)
{
distance =
cout << "Distance to hole " << counter << " is " << distance << " yards."
int main()
{
randomize();
Introduction();
return(0);
}