Last active
February 18, 2024 10:07
-
-
Save bobblanchett/205fe68470c49d62aa36af608a9b6719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace AreaRectSquareTriCircle | |
{ | |
internal class Program | |
/* | |
* Area and Perimeter of Rectangle, Square, Triangle & Circle. | |
* Bob Blanchett SN100639184 16/2/24 | |
* reusing the code from the previous RSP/Sha exercise, I have added shapes to the switch statement. | |
*/ | |
{ | |
static void Main(string[] args) | |
{ | |
while (true) // loop to keep the choice alive until exit is chosen. | |
{ | |
Console.WriteLine("Shape Area and Perimeter Calculator."); | |
Console.WriteLine("Please enter your choice: rectangle, square, triangle, circle or exit."); | |
switch (Console.ReadLine()) | |
{ | |
case "rectangle": | |
Console.WriteLine("Please enter the length of the rectangle:"); | |
double Rlength = double.Parse(Console.ReadLine()); | |
Console.WriteLine("Please enter the width of the rectangle:"); | |
double Rwidth = double.Parse(Console.ReadLine()); | |
double Rarea = Rlength * Rwidth; | |
double Rperimeter = 2 * (Rlength + Rwidth); | |
Console.WriteLine($"The area of the rectangle of length {Rlength} is: {Rarea}"); | |
Console.WriteLine($"The perimeter of the rectangle of length {Rlength} and width {Rwidth} is: {Rperimeter}"); | |
break; | |
case "square": | |
Console.WriteLine("Please enter the length of the square:"); | |
double Slength = double.Parse(Console.ReadLine()); | |
double Sarea = Slength * Slength; | |
double Sperimeter = 4 * Slength; | |
Console.WriteLine($"The area of the square of length {Slength} is: {Sarea}"); | |
Console.WriteLine($"The perimeter of the square of length {Slength} is: {Sperimeter}"); | |
break; | |
case "triangle": | |
Console.WriteLine("Please enter the base of the Rt Angle triangle:"); | |
double Tbase = double.Parse(Console.ReadLine()); | |
Console.WriteLine("Please enter the height of the Rt Angle triangle:"); | |
double Theight = double.Parse(Console.ReadLine()); | |
double TArea = 0.5 * (Tbase * Theight); | |
Console.WriteLine($"The area of the Rt Angle triangle of base {Tbase} and height {Theight} is: {TArea}"); | |
Console.WriteLine($"Please enter the length of the first side of the triangle of base length {Tbase}:"); | |
double Tside1 = double.Parse(Console.ReadLine()); | |
Console.WriteLine($"Please enter the length of the second side of the triangle of base length {Tbase}:"); | |
double Tside2 = double.Parse(Console.ReadLine()); | |
double TPerimeter = Tbase + Tside1 + Tside2; | |
Console.WriteLine($"The perimeter of the triangle of base length {Tbase} and side lengths {Tside1} and {Tside2} is: {TPerimeter}"); | |
break; | |
case "circle": | |
Console.WriteLine("Please enter the radius of the circle:"); | |
double Cradius = double.Parse(Console.ReadLine()); | |
double Carea = Math.PI * Cradius * Cradius; | |
double Cperimeter = 2 * Math.PI * Cradius; | |
Console.WriteLine($"The area of the circle of radius {Cradius} is: {Carea}"); | |
Console.WriteLine($"The perimeter of the circle of radius {Cradius} is: {Cperimeter}"); | |
break; | |
case "exit": | |
Console.WriteLine("Goodbye!"); | |
return; | |
default: | |
Console.WriteLine("Invalid input. Please try again."); | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment