You are to write a golf game that allows the user to play one hole, a 280 metre par 5.
For each swing, the player chooses a club and then the program generates the distance hit for each shot, updating the distance to the hole accordingly. Play proceeds until the ball is in the hole (distance to the hole is zero), and then the program informs the user of their score.
The player (user) has three clubs to choose from for each shot. Each club hits the ball a certain average distance, but the actual distance hit randomly varies between 80% and 120% of the average.
The clubs and their average distances are:
• Driver: 100m
• Iron: 30m
• Putter: 10m*
*When the ball is inside 10m and the putter is used, the shot will be between 80% and 120% of the distance to the hole, not the club’s distance. The minimum distance the putter can hit is 1m (no 0m hits). All distances are whole numbers.
If an invalid club is chosen, this is counted as an air swing and the number of shots increases by one, but the ball doesn’t move.
The ball cannot be a negative distance to the hole. Whether it is in front of or behind the hole, it is still a positive distance to the hole.
The score is the number of shots taken to get the ball in the hole. The final output shows the number of shots taken and how this relates to par. Less than par (5 in this case) is “under par”, equal to 5 is called “par”, and more than 5 is “over par”.