52.4k views
2 votes
Please make a Console application that allows users to input

height and width of a rectangle. It outputs the area and
perimeter.
C#

User Tom Wang
by
9.7k points

1 Answer

5 votes

Final answer:

To calculate the area and perimeter of a rectangle in a C# console application, prompt the user for input, convert the input to doubles, perform the calculations, and display the results.

Step-by-step explanation:

To create a Console application in C# that calculates the area and perimeter of a rectangle based on user inputted height and width, you can use the following code structure:

using System;
class Program
{
static void Main()
{
Console.WriteLine("Please enter the height of the rectangle:");
double height = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("Please enter the width of the rectangle:");
double width = Convert.ToDouble(Console.ReadLine());

double area = height * width;
double perimeter = 2 * (height + width);

Console.WriteLine("The area of the rectangle is: " + area);
Console.WriteLine("The perimeter of the rectangle is: " + perimeter);
}
}This program first prints instructions asking the user to enter the height and width of a rectangle. After reading the user's input, it converts the string inputs to double data types using Convert.ToDouble. It then calculates the area by multiplying the height and width and calculates the perimeter by taking the sum of twice the height and twice the width. Finally, it prints out the calculated area and perimeter to the console.

User Ronie Martinez
by
7.9k points