Objective
Write a C# program to ask the user for their age (e.g. 20) and respond with something like "You look younger than 20" (the age entered by the user should be displayed in place of "20").
Write Your C# Exercise
C# Exercise Example
using System; // Importing the System namespace to use Console functionalities
// Main class of the program
class Program
{
// Main method where the program execution begins
static void Main()
{
// Declaring a variable to store the user's age
int age;
// Asking the user to enter their age and reading the input
Console.Write("Please enter your age: ");
age = Convert.ToInt32(Console.ReadLine());
// Printing the response with the age entered by the user
Console.WriteLine("You look younger than {0}", age);
}
}
Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.
This C# exercise teaches you how to handle console output using two different methods: Console.Write and formatting with {0}. In this program, the user will in...
This C# exercise helps you practice using loops and user input. In this program, the user will be asked to input a number (a digit), and the program will display a re...
This C# exercise teaches you how to perform temperature unit conversions. The program prompts the user to input a temperature in Celsius degrees and then converts it ...
This exercise is an excellent way to get started with programming in C#. In this program, you will learn how to print a message on the screen using C#. The program wi...
This exercise is a great way to practice basic arithmetic operations in C#. In this program, you will learn how to perform an addition operation between two numbers, 12 and ...
This exercise is a great opportunity to practice the division operation in C#. In this program, you will learn how to divide two numbers, in this case, 24 and 5, and ...