0
0
Goprogramming~15 mins

Nested conditional statements in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested Conditional Statements
๐Ÿ“– Scenario: You are creating a simple program to check a person's age and membership status to decide their ticket price for a movie theater.
๐ŸŽฏ Goal: Build a Go program that uses nested conditional statements to determine the ticket price based on age and membership.
๐Ÿ“‹ What You'll Learn
Create a variable age with an integer value
Create a variable isMember with a boolean value
Use nested if statements to check age and isMember
Print the correct ticket price based on the conditions
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Nested conditions help in real life when decisions depend on multiple factors, like pricing tickets based on age and membership.
๐Ÿ’ผ Career
Understanding nested conditionals is important for writing clear decision-making code in many programming jobs.
Progress0 / 4 steps
1
Create variables for age and membership
Create a variable called age and set it to 20. Create a variable called isMember and set it to true.
Go
Need a hint?

Use var to declare variables with their types and assign the exact values.

2
Add a variable for base ticket price
Create a variable called ticketPrice and set it to 15.
Go
Need a hint?

Use var ticketPrice int = 15 to set the starting price.

3
Use nested if statements to adjust ticket price
Use nested if statements to check if age is less than 18. Inside that, check if isMember is true. If both are true, set ticketPrice to 5. Otherwise, if age is 18 or more and isMember is true, set ticketPrice to 10.
Go
Need a hint?

Use nested if inside another if and an else block to check conditions step by step.

4
Print the final ticket price
Write a fmt.Println statement to print the text "Ticket price: " followed by the value of ticketPrice.
Go
Need a hint?

Use fmt.Println("Ticket price:", ticketPrice) to show the final price.