Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Start:
- Console.WriteLine("Enter corresponding number to select shape");
- Console.WriteLine("Square: 1 Rectangle: 2 Triangle: 3 Circle: 4");
- int n = 0;
- while(!int.TryParse(Console.ReadLine(), out n) || n < 1 || n > 4)
- {
- Console.WriteLine("Error, enter again");
- }
- switch(n)
- {
- case 1:
- float sh;
- Console.WriteLine("Enter the height");
- while(!float.TryParse(Console.ReadLine(), out sh))
- {
- Console.WriteLine("Error, enter again");
- }
- Console.WriteLine(Square(sh));
- break;
- case 2:
- float rh;
- float rw;
- Console.WriteLine("Enter height and width separated by a space");
- string[] s = Console.ReadLine().Split(' ');
- while(s.Length != 2 || !float.TryParse(s[0], out rh) || !float.TryParse(s[2], out rw))
- {
- Console.WriteLine("Error, enter again");
- s = Console.ReadLine().Split(' ');
- }
- Console.WriteLine(Rectangle(float.Parse(s[0]), float.Parse(s[1])));
- break;
- case 3:
- float tb;
- float th;
- Console.WriteLine("Enter base and height separated by a space");
- string[] t = Console.ReadLine().Split(' ');
- while(t.Length!= 2 || !float.TryParse(t[0], out tb) || !float.TryParse(t[2], out th))
- {
- Console.WriteLine("Error, enter again");
- t = Console.ReadLine().Split(' ');
- }
- Console.WriteLine(Triangle(tb, th));
- break;
- case 4:
- Console.WriteLine("Enter the radius");
- float r;
- while(!float.TryParse(Console.ReadLine(), out r))
- {
- Console.WriteLine("Error, enter again");
- }
- Console.WriteLine(Circle(r));
- break;
- }
- Console.WriteLine("Press any key to continue...");
- Console.ReadKey();
- goto Start;
- private float Square(float w)
- {
- return w * w;
- }
- private float Rectangle(float w, float h)
- {
- return w * h;
- }
- private float Triangle(float b, float h)
- {
- return 0.5f * b * h;
- }
- private float Circle(float r)
- {
- return (float)Math.PI * r * r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement