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

C# program to input a height and print its (a person) category as Dwarf, Average, and Tall.
Submitted by Nidhi, on August 17, 2020

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.

Program:

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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.