SlideShare a Scribd company logo
OptionExplicit
Submain()
'Main starts by askingthe userfortheirname and thenstoresitas a variable.userNameisusedfor
bothgreetingandsayingfarewelltothe user.It startsby turningwhateverinputthe userentersinto
'a capital letter.Iuseda seriesof dowhile loopsforthe menuwitherrorcheckingineachloop.
DimuserName AsString
DimmenuChoice AsString
DiminstructionsAsString
DimbeginGolf AsString
userName =InputBox("Enteryourname")
MsgBox ("Let's playgolf " & userName &"!")
menuChoice =UCase(InputBox("Choose fromthe followingoptions:"&vbNewLine &"(I)
Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit"))
Do While menuChoice <>"Q" AndmenuChoice <>"P" AndmenuChoice <>"I"
MsgBox ("Invalidmenuselection,pleaseenterI,Por Q")
menuChoice=UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine&"(I)
Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine & "(Q) Quit"))
Loop
Do While menuChoice ="I"
MsgBox ("Thisisa simple golf game inwhichyouwill playa230m game of golf withpar 5. You are
able to choose from3 clubs,the Driver,Ironor Putter.The Driverwill hitaround100m, the Iron
around30m and the Putteraround10m. The putterisbestusedveryclose tothe hole.")
menuChoice=UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine&"(I)
Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit"))
Do While menuChoice <>"Q" AndmenuChoice <>"P" AndmenuChoice <>"I"
MsgBox ("Invalidmenuselection,please enterI,Por Q")
menuChoice =UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine &"(I)
Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit"))
Loop
Loop
Do While menuChoice ="P"
beginGolf =playGolf
menuChoice=UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine&"(I)
Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit"))
Do While menuChoice ="I"
MsgBox ("Thisisa simple golf game in whichyouwill playa230m game of golf withpar 5.
You are able tochoose from3 clubs,the Driver,Ironor Putter.The Driverwill hitaround100m, the
Iron around30m and the Putteraround10m. The putteris bestusedveryclose tothe hole.")
menuChoice =UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine &"(I)
Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit"))
Loop
Do While menuChoice <>"Q" AndmenuChoice <>"P" AndmenuChoice <>"I"
MsgBox ("Invalidmenuselection,pleaseenterI,Por Q")
menuChoice=UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine&"(I)
Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit"))
Loop
Loop
If menuChoice ="Q" Then
MsgBox ("Thanksforplaying"& userName)
ExitSub
End If
End Sub
FunctionplayGolf()
' playGolf iswhere the entiretyof the game plays out.Itstarts by settingthe absolute distance tothe
hole to230 and thenstarts a loopwhichrepeatedlygetsaclubselectionfromthe useruntil
' theyhave sunkthe ball intothe hole.Iterror checksforinvalidclubselectionsthroughout
gameplayaswell,anduponan invalidclubinformsthe userof thisandaddsa swingcountto their
par score.
' All the clubdistancesare declaredasvariablesandusedinassosciationwithrandomDistance as
thiswas the mostintuitive waytogenerate arandomdistance forme.Dependingonhow many
swings
' the usertookto sinkthe ball a congratulationsmessage box appearsinformingthemif theywere
under,onor over par.Aftera game isplayedoutitreturnsto the menu.
DimclubSelectionAsString
DimdistanceToHole AsInteger
DimdistanceHitAsInteger
DimswingsAsInteger
DimrandomDistance AsDouble
ConstDRIVER_DISTANCE= 100
ConstIRON_DISTANCE= 30
ConstPUTTER_DISTANCE = 10
distanceToHole =Abs(230)
swings= 0
Do Until distanceToHole =0
clubSelection=UCase(InputBox("Youare "& distanceToHole &"m" & " fromhole"&
vbNewLine&"Clubselection:pressDfordriver,I forIron, Pfor Putter"))
randomDistance =Int((120 - 80) * Rnd+ 80) / 100
Do While clubSelection<>"D" AndclubSelection<>"I" AndclubSelection<>"P"
MsgBox ("Invalidclubselection=air swing:( Your shotwent0m. You are " &
distanceToHole &"mfromthe hole,after"& swings& " shot/s")
swings= swings+ 1
clubSelection=UCase(InputBox("Youare "& distanceToHole &"m" & " fromhole"&
vbNewLine&"Clubselection:pressDfordriver,I forIron, Pfor Putter"))
Loop
If clubSelection="D" Then
distanceHit=randomDistance * DRIVER_DISTANCE
ElseIf clubSelection="I"Then
distanceHit=randomDistance * IRON_DISTANCE
ElseIf clubSelection="P"Then
If distanceToHole<=10 Then
distanceHit= distanceToHole*Int((120 - 80) * Rnd + 80) / 100
Else
distanceHit= randomDistance *PUTTER_DISTANCE
End If
End If
swings= swings+ 1
distanceToHole =Abs(distanceToHole- distanceHit)
MsgBox ("Your shotwent" & distanceHit&"m " & "youare " & distanceToHole&"mfrom
the hole"& " after" & swings&" shot/s")
Loop
If swings< 5 Then
MsgBox ("Clunk...Congratulations"&"after " & swings& " hits"& " you are " & 5 - swings&"
underpar")
ElseIf swings=5 Then
MsgBox ("Clunk...Congratulations"&" after" & swings&" hits"& " youmade par")
Else
MsgBox ("Clunk...Dissappointing"&" after" & swings& " hits"& " youare " & swings -
5 & " overpar")
End If
End Function

More Related Content

Viewers also liked

Latino bi ven-presentación_cliente
Latino bi ven-presentación_clienteLatino bi ven-presentación_cliente
Latino bi ven-presentación_clientehylennegonzalez
 
обзор изменений российского законодательства 02.11 06.11
обзор изменений российского законодательства 02.11 06.11обзор изменений российского законодательства 02.11 06.11
обзор изменений российского законодательства 02.11 06.11
Olga Kravtsova
 
обзор изменений российского законодательства 25.01 29.01
обзор изменений российского законодательства 25.01 29.01обзор изменений российского законодательства 25.01 29.01
обзор изменений российского законодательства 25.01 29.01
Olga Kravtsova
 
обзор изменений российского законодательства 30.11 04.12
обзор изменений российского законодательства 30.11 04.12обзор изменений российского законодательства 30.11 04.12
обзор изменений российского законодательства 30.11 04.12
Olga Kravtsova
 
обзор изменений российского законодательства 24.02.2016 26.02.2016
обзор изменений российского законодательства 24.02.2016 26.02.2016обзор изменений российского законодательства 24.02.2016 26.02.2016
обзор изменений российского законодательства 24.02.2016 26.02.2016
Olga Kravtsova
 
Vinay Gupta - Software QA Lead - Around 9 Years experience
Vinay Gupta - Software QA Lead - Around 9 Years experienceVinay Gupta - Software QA Lead - Around 9 Years experience
Vinay Gupta - Software QA Lead - Around 9 Years experienceVinay Kumar Gupta
 
Lugares para vacacionar completo
Lugares para vacacionar completoLugares para vacacionar completo
Lugares para vacacionar completo
delfinabicerne
 
Bilal_Kassab_Talent_Profile
Bilal_Kassab_Talent_ProfileBilal_Kassab_Talent_Profile
Bilal_Kassab_Talent_ProfileBilal Kassab
 
QTP 9.2
QTP 9.2QTP 9.2
Styling Dir - F21 1.13 EU
Styling Dir - F21 1.13 EUStyling Dir - F21 1.13 EU
Styling Dir - F21 1.13 EUJaia Owens
 

Viewers also liked (11)

Latino bi ven-presentación_cliente
Latino bi ven-presentación_clienteLatino bi ven-presentación_cliente
Latino bi ven-presentación_cliente
 
обзор изменений российского законодательства 02.11 06.11
обзор изменений российского законодательства 02.11 06.11обзор изменений российского законодательства 02.11 06.11
обзор изменений российского законодательства 02.11 06.11
 
обзор изменений российского законодательства 25.01 29.01
обзор изменений российского законодательства 25.01 29.01обзор изменений российского законодательства 25.01 29.01
обзор изменений российского законодательства 25.01 29.01
 
обзор изменений российского законодательства 30.11 04.12
обзор изменений российского законодательства 30.11 04.12обзор изменений российского законодательства 30.11 04.12
обзор изменений российского законодательства 30.11 04.12
 
обзор изменений российского законодательства 24.02.2016 26.02.2016
обзор изменений российского законодательства 24.02.2016 26.02.2016обзор изменений российского законодательства 24.02.2016 26.02.2016
обзор изменений российского законодательства 24.02.2016 26.02.2016
 
Vinay Gupta - Software QA Lead - Around 9 Years experience
Vinay Gupta - Software QA Lead - Around 9 Years experienceVinay Gupta - Software QA Lead - Around 9 Years experience
Vinay Gupta - Software QA Lead - Around 9 Years experience
 
Korte_MRI_SOT 2015
Korte_MRI_SOT 2015Korte_MRI_SOT 2015
Korte_MRI_SOT 2015
 
Lugares para vacacionar completo
Lugares para vacacionar completoLugares para vacacionar completo
Lugares para vacacionar completo
 
Bilal_Kassab_Talent_Profile
Bilal_Kassab_Talent_ProfileBilal_Kassab_Talent_Profile
Bilal_Kassab_Talent_Profile
 
QTP 9.2
QTP 9.2QTP 9.2
QTP 9.2
 
Styling Dir - F21 1.13 EU
Styling Dir - F21 1.13 EUStyling Dir - F21 1.13 EU
Styling Dir - F21 1.13 EU
 

Recently uploaded

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 

Recently uploaded (20)

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 

Golf game vba code

  • 1. OptionExplicit Submain() 'Main starts by askingthe userfortheirname and thenstoresitas a variable.userNameisusedfor bothgreetingandsayingfarewelltothe user.It startsby turningwhateverinputthe userentersinto 'a capital letter.Iuseda seriesof dowhile loopsforthe menuwitherrorcheckingineachloop. DimuserName AsString DimmenuChoice AsString DiminstructionsAsString DimbeginGolf AsString userName =InputBox("Enteryourname") MsgBox ("Let's playgolf " & userName &"!") menuChoice =UCase(InputBox("Choose fromthe followingoptions:"&vbNewLine &"(I) Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit")) Do While menuChoice <>"Q" AndmenuChoice <>"P" AndmenuChoice <>"I" MsgBox ("Invalidmenuselection,pleaseenterI,Por Q") menuChoice=UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine&"(I) Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine & "(Q) Quit")) Loop Do While menuChoice ="I" MsgBox ("Thisisa simple golf game inwhichyouwill playa230m game of golf withpar 5. You are able to choose from3 clubs,the Driver,Ironor Putter.The Driverwill hitaround100m, the Iron around30m and the Putteraround10m. The putterisbestusedveryclose tothe hole.") menuChoice=UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine&"(I) Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit")) Do While menuChoice <>"Q" AndmenuChoice <>"P" AndmenuChoice <>"I"
  • 2. MsgBox ("Invalidmenuselection,please enterI,Por Q") menuChoice =UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine &"(I) Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit")) Loop Loop Do While menuChoice ="P" beginGolf =playGolf menuChoice=UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine&"(I) Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit")) Do While menuChoice ="I" MsgBox ("Thisisa simple golf game in whichyouwill playa230m game of golf withpar 5. You are able tochoose from3 clubs,the Driver,Ironor Putter.The Driverwill hitaround100m, the Iron around30m and the Putteraround10m. The putteris bestusedveryclose tothe hole.") menuChoice =UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine &"(I) Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit")) Loop Do While menuChoice <>"Q" AndmenuChoice <>"P" AndmenuChoice <>"I" MsgBox ("Invalidmenuselection,pleaseenterI,Por Q") menuChoice=UCase(InputBox("Choosefromthe followingoptions:"&vbNewLine&"(I) Instructions"&vbNewLine &"(P) Playgolf"&vbNewLine &"(Q) Quit")) Loop Loop If menuChoice ="Q" Then MsgBox ("Thanksforplaying"& userName) ExitSub End If End Sub FunctionplayGolf()
  • 3. ' playGolf iswhere the entiretyof the game plays out.Itstarts by settingthe absolute distance tothe hole to230 and thenstarts a loopwhichrepeatedlygetsaclubselectionfromthe useruntil ' theyhave sunkthe ball intothe hole.Iterror checksforinvalidclubselectionsthroughout gameplayaswell,anduponan invalidclubinformsthe userof thisandaddsa swingcountto their par score. ' All the clubdistancesare declaredasvariablesandusedinassosciationwithrandomDistance as thiswas the mostintuitive waytogenerate arandomdistance forme.Dependingonhow many swings ' the usertookto sinkthe ball a congratulationsmessage box appearsinformingthemif theywere under,onor over par.Aftera game isplayedoutitreturnsto the menu. DimclubSelectionAsString DimdistanceToHole AsInteger DimdistanceHitAsInteger DimswingsAsInteger DimrandomDistance AsDouble ConstDRIVER_DISTANCE= 100 ConstIRON_DISTANCE= 30 ConstPUTTER_DISTANCE = 10 distanceToHole =Abs(230) swings= 0 Do Until distanceToHole =0 clubSelection=UCase(InputBox("Youare "& distanceToHole &"m" & " fromhole"& vbNewLine&"Clubselection:pressDfordriver,I forIron, Pfor Putter")) randomDistance =Int((120 - 80) * Rnd+ 80) / 100 Do While clubSelection<>"D" AndclubSelection<>"I" AndclubSelection<>"P" MsgBox ("Invalidclubselection=air swing:( Your shotwent0m. You are " & distanceToHole &"mfromthe hole,after"& swings& " shot/s") swings= swings+ 1
  • 4. clubSelection=UCase(InputBox("Youare "& distanceToHole &"m" & " fromhole"& vbNewLine&"Clubselection:pressDfordriver,I forIron, Pfor Putter")) Loop If clubSelection="D" Then distanceHit=randomDistance * DRIVER_DISTANCE ElseIf clubSelection="I"Then distanceHit=randomDistance * IRON_DISTANCE ElseIf clubSelection="P"Then If distanceToHole<=10 Then distanceHit= distanceToHole*Int((120 - 80) * Rnd + 80) / 100 Else distanceHit= randomDistance *PUTTER_DISTANCE End If End If swings= swings+ 1 distanceToHole =Abs(distanceToHole- distanceHit) MsgBox ("Your shotwent" & distanceHit&"m " & "youare " & distanceToHole&"mfrom the hole"& " after" & swings&" shot/s") Loop If swings< 5 Then MsgBox ("Clunk...Congratulations"&"after " & swings& " hits"& " you are " & 5 - swings&" underpar") ElseIf swings=5 Then MsgBox ("Clunk...Congratulations"&" after" & swings&" hits"& " youmade par") Else MsgBox ("Clunk...Dissappointing"&" after" & swings& " hits"& " youare " & swings - 5 & " overpar")