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

Comparison operators in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Comparison operators
📖 Scenario: You are creating a simple program to compare ages of two friends to see who is older.
🎯 Goal: Build a program that stores two ages, compares them using comparison operators, and prints the results.
📋 What You'll Learn
Create two integer variables with exact ages
Create a boolean variable to store the comparison result
Use comparison operators to compare the ages
Print the comparison results exactly as specified
💡 Why This Matters
🌍 Real World
Comparing values is common in programs that make decisions, like checking user age for access or sorting data.
💼 Career
Understanding comparison operators is essential for writing conditions and logic in any software development job.
Progress0 / 4 steps
1
Create age variables
Create two integer variables called ageAlice and ageBob with values 25 and 30 respectively.
C Sharp (C#)
Need a hint?

Use int to declare the variables and assign the exact values.

2
Create comparison variables
Create two boolean variables called isAliceOlder and isBobOlder without assigning values yet.
C Sharp (C#)
Need a hint?

Declare boolean variables using bool keyword.

3
Compare ages using comparison operators
Assign isAliceOlder to the result of ageAlice > ageBob and isBobOlder to the result of ageBob > ageAlice.
C Sharp (C#)
Need a hint?

Use the greater than operator > to compare the ages.

4
Print the comparison results
Print the values of isAliceOlder and isBobOlder using Console.WriteLine exactly as shown: "Is Alice older? {isAliceOlder}" and "Is Bob older? {isBobOlder}".
C Sharp (C#)
Need a hint?

Use Console.WriteLine with string interpolation $"...{variable}..." to print the results.