static decimal pi = 3.14159M;
private static decimal cone(decimal r, decimal h)
return 1 / 3M * pi * r2 * h;
private static decimal sphere(decimal r)
private static decimal cylinder(decimal r, decimal h)
public static void Main()
string restart = "qwertyuiop";
while (restart != "q" && restart != "Q")
Console.WriteLine("Would you like to find the volume of a cone, sphere, or cylinder? (You can enter 'co', 'sph', or 'cyl'.)");
string shape = Console.ReadLine();
if (shape == "co" || shape == "cone" || shape == "Cone")
Console.WriteLine("Please enter the radius:");
rad = Console.ReadLine();
if (decimal.TryParse(rad, out ans))
Console.WriteLine("Please enter a positive number.");
Console.WriteLine("Please enter a valid number.");
Console.WriteLine("Please enter the height:");
height = Console.ReadLine();
if (decimal.TryParse(height, out ans2))
Console.WriteLine("Please enter a positive number.");
Console.WriteLine("The volume of the cone is " + cone(ans, ans2).ToString("##.##") + "."); }
Console.WriteLine("Please enter a valid number.");
Console.WriteLine("The volume of the cone is " + cone(ans, ans2).ToString("##.##") + ".");
else if (shape == "sph" || shape == "sphere" || shape == "Sphere")
Console.WriteLine("Please enter the radius:");
rad = Console.ReadLine();
if (decimal.TryParse(rad, out ans))
Console.WriteLine("Please enter a positive number.");
Console.WriteLine("Please enter a valid number.");
Console.WriteLine("The volume of the sphere is " + sphere(ans).ToString("##.##") + ".");
else if (shape == "cyl" || shape == "cylinder" || shape == "Cylinder")
Console.WriteLine("Please enter the radius:");
rad = Console.ReadLine();
if (decimal.TryParse(rad, out ans))
Console.WriteLine("Please enter a positive number.");
Console.WriteLine("Please enter a valid number.");
Console.WriteLine("Please enter the height:");
height = Console.ReadLine();
if (decimal.TryParse(height, out ans2))
Console.WriteLine("Please enter a positive number.");
Console.WriteLine("Please enter a valid number.");
Console.WriteLine("The volume of the cylinder is " + cylinder(ans, ans2).ToString("##.##") + ".");
Console.WriteLine("Please enter 'cone', 'sphere', or 'cylinder.' (You can also enter 'co', 'sph', or 'cyl'.)");
Console.WriteLine("Program restarting... enter 'q' to quit. Enter anything else to continue.");
restart = Console.ReadLine();