0
0
C Sharp (C#)programming~15 mins

Nested conditional execution in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested Conditional Execution
📖 Scenario: You are creating a simple program to help a coffee shop decide the price of a coffee order based on the size and whether the customer wants extra syrup.
🎯 Goal: Build a program that uses nested if statements to determine the final price of a coffee order based on size and syrup option.
📋 What You'll Learn
Create a variable size with the exact value "medium".
Create a variable extraSyrup with the exact value true.
Use nested if statements to set the price variable based on size and extraSyrup.
Print the final price using Console.WriteLine.
💡 Why This Matters
🌍 Real World
Coffee shops and many other businesses use nested conditions to calculate prices based on options customers choose.
💼 Career
Understanding nested conditional execution is essential for programming tasks like pricing, form validation, and decision-making in software.
Progress0 / 4 steps
1
Create initial variables
Create a string variable called size and set it to "medium". Create a boolean variable called extraSyrup and set it to true.
C Sharp (C#)
Need a hint?

Use string size = "medium"; and bool extraSyrup = true; to create the variables.

2
Add price variable
Create a double variable called price and set it to 0.
C Sharp (C#)
Need a hint?

Use double price = 0; to create the price variable.

3
Use nested if statements to set price
Use nested if statements with size and extraSyrup to set price as follows:
- If size is "small", price is 2.0, add 0.5 if extraSyrup is true.
- If size is "medium", price is 3.0, add 0.5 if extraSyrup is true.
- If size is "large", price is 4.0, add 0.5 if extraSyrup is true.
C Sharp (C#)
Need a hint?

Use nested if inside each size check to add 0.5 if extraSyrup is true.

4
Print the final price
Use Console.WriteLine to print the text "Final price: " followed by the price variable.
C Sharp (C#)
Need a hint?

Use Console.WriteLine("Final price: " + price); to print the result.