The teacher asked us to make a program asking the following:
Your program this week is:
1. Design a program that will keep track of a users golf score and let him/her know how far over or under par they are.
2. The program should accept the following input from the user:
a. Golfers Name
b. Amount of strokes the Golfer just had on the current hole, for 18 holes.
3. The program should prompt the golfer for the number of strokes on the just finished hole( EX. How many strokes did you have on hole 4?)
4. The program should keep track of the golfer’s total strokes and compare it to the current par. The program should let the golfer know how he/she is doing after data is entered for each hole (You are currently 3 over par).
Par refers to the number of strokes that it should take you to get the golf ball in the hole. If a hole is listed as par 3 and it takes you 4 strokes to get the ball in the hole, then you are one over par. If you get the ball in the hole in 2 strokes, then you are one under par. If the total par for 18 holes is 54 and you had a total of 60 strokes to complete the course, then you are 6 over par.
5. The following holes are par 3:
a. 1, 4 ,5, 7, 17
6. The following holes are par 4:
a. 2, 3, 6, 11, 12, 15
7. The following holes are par 5:
a. 8, 9, 10, 13, 14, 16
8. The following hole is par 8:
a. 18
9. When the golfer finishes all 18 holes the scorecard should be output to the screen. The scorecard should show the hole number, par for the hole, and the golfers strokes for the hole. It should also show the total par, and total strokes.
10. A message should be displayed based on the golfers score compared to par. Different messages should be displayed based on over par, under par, or exactly par.
I have so far:
- Code: Select all
#include <iostream>
using namespace std;
int main()
{
string firstname, lastname;
int hol1, hol2, hol3, hol4, hol5, hol6, hol7, hol8, hol9, hol10;
int par;
int holes[18] = {3, 4, 4, 3, 4, 4, 3, 5, 5, 5, 4, 4, 5, 5, 4, 5, 3, 8};
cout << "Enter golfers name: ";
cin >> firstname >> lastname;
cout <<"Your name is " << firstname << " " << lastname << endl;
//hole1
cout << "Enter your strokes for hole 1: ";
cin >> hol1;
par = hol1 - holes[0];
if (hol1 < holes[0])
{
cout << "you are " << par << " under par, Great Job!\n";
}
else
cout << "you are " << par << " over par.\n";
// Hole 2
cout << "Enter your strokes for hole 2: ";
cin >> hol2;
par = hol2 - holes[1];
if (hol2 < holes[1])
{
cout << "you are " << par << " under par, Great Job!\n";
}
else
cout << "you are " << par << " over par.\n";
//hole3
cout << "Enter your strokes for hole 3: ";
cin >> hol3;
par = hol3 - holes[2];
if (hol3 < holes[2])
{
cout << "you are " << par << " under par, Great Job!\n";
}
else
cout << "you are " << par << " over par.\n";
//hole4
cout << "Enter your strokes for hole 4: ";
cin >> hol4;
par = hol4 - holes[3];
if (hol4 < holes[3])
{
cout << "you are " << par << " under par, Great Job!\n";
}
else
cout << "you are " << par << " over par.\n";
//hole5
cout << "Enter your strokes for hole 5: ";
cin >> hol5;
par = hol5 - holes[4];
if (hol5 < holes[4])
{
cout << "you are " << par << " under par, Great Job!\n";
}
else
cout << "you are " << par << " over par.\n";
//hole6
cout << "Enter your strokes for hole 6: ";
cin >> hol6;
par = hol6 - holes[5];
if (hol6 < holes[5])
{
cout << "you are " << par << " under par, Great Job!\n";
}
else
cout << "you are " << par << " over par.\n";
system ("pause");
return 0;
}
Is there a way to simplify this instead of me doing the 18 holes how I have started?


