C#: Accept the height of a person in centimeter and categorize them
C# Sharp Conditional Statement: Exercise-7 with Solution
Write a C# Sharp program to accept a person's height in centimeters and categorize them according to their height.
Sample Solution:-
C# Sharp Code:
using System; // Importing the System namespace
public class Exercise7 // Declaration of the Exercise7 class
{
public static void Main() // Entry point of the program
{
float PerHeight; // Declaration of the float variable PerHeight to store the height of the person
Console.Write("\n\n"); // Printing new lines
Console.Write("Accept the height of a person in centimeter and categorize them:\n"); // Displaying the purpose of the program
Console.Write("----------------------------------------------------------------"); // Displaying a separator
Console.Write("\n\n"); // Printing new lines
Console.Write("Input the height of the person (in centimetres):"); // Prompting user to input the height
PerHeight = Convert.ToInt32(Console.ReadLine()); // Reading the input height of the person from the user
if (PerHeight < 150.0) // Checking if the height is less than 150 centimeters
Console.Write("The person is Dwarf. \n\n"); // Printing a message if the person is categorized as a dwarf
else if ((PerHeight >= 150.0) && (PerHeight <= 165.0)) // Checking if the height is between 150 and 165 centimeters
Console.Write("The person is average heighted. \n\n"); // Printing a message if the person is categorized as average heighted
else if ((PerHeight >= 165.0) && (PerHeight <= 195.0)) // Checking if the height is between 165 and 195 centimeters
Console.Write("The person is taller. \n\n"); // Printing a message if the person is categorized as taller
else
Console.Write("Abnormal height.\n\n"); // Printing a message if the height is not within the specified ranges
}
}
Sample Output:
Accept the height of a person in centimeter and categorize them: ---------------------------------------------------------------- Input the height of the person (in centimetres):190 The person is taller.
Visual Presentation:
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C# Sharp program to read the value of an integer m and display the value of n is 1 when m is larger than 0, 0 when m is 0 and -1 when m is less than 0.
Next: Write a C program to find the largest of three numbers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/csharp-exercises/conditional-statement/csharp-conditional-statement-exercise-7.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics