C# - Accept Height, Print Category as Dwarf, Average, and Tall

In this example, we are going to learn take height as input and print its category as Dwarf, Average, and Tall using C# program?
Submitted by Nidhi, on August 17, 2020 [Last updated : March 22, 2023]

Printing category as dwarf, average, and tall based on height

Here we will create a C# program that takes height as input and print its category as Dwarf, Average, and Tall.

  1. For the "Tall" height person we checked condition, height must be greater than 170 cm.
  2. For the "Average" height person we checked condition, height must be between 160 and 170 cm.
  3. For the "Dwarf" height person we checked condition, height must be less than 160 cm.

C# program to take height as input and print its category as Dwarf, Average, and Tall

The source code to print the height category in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//Program to take height as input and print 
//its category as Dwarf, Average, and Tall.

using System;

class program
{
    public static void Main()
    {
        int height=0;
        
        Console.WriteLine("Enter your Height (in centimeters): ");
        height = int.Parse(Console.ReadLine());

        if (height < 160)
            Console.WriteLine("You are Dwarf person");
        else if ((height >= 160) && (height <= 170))
            Console.WriteLine("You are average height person");
        else if (height >= 170)
            Console.WriteLine("You are tall person");
        else
            Console.WriteLine("Entered height is abnormal");
    }
}

Output

Enter your Height (in centimeters):
172
You are tall person
Press any key to continue . . .

Explanation

In the above program, we created a program class that contains Main() method, In the Main() method we created a local variable height initialized with 0. Then we took height as an input, and then check conditions and print the appropriate message on the console screen.

C# Basic Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.