本文整理汇总了C#中Volume.sphereVolume方法的典型用法代码示例。如果您正苦于以下问题:C# Volume.sphereVolume方法的具体用法?C# Volume.sphereVolume怎么用?C# Volume.sphereVolume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Volume
的用法示例。
在下文中一共展示了Volume.sphereVolume方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
int selection = 0;
double length, height, radius, volume;
Volume vol = new Volume();
while (selection != 4)
{
selection = 0;
while (selection < 1 || selection > 4)
{
Console.WriteLine("1. Cube Volume\n2. Cylinder Volume\n3. Sphere Volume\n4. Exit");
Console.Write("Select from the menu: ");
// Need to add exception handling here
try
{
selection = int.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("Select a valid option!");
selection = 0;
}
}
Console.WriteLine();
switch (selection)
{
case 1:
Console.Write("Enter the length of a cube side: ");
length = Convert.ToDouble(Console.ReadLine());
volume = vol.cubeVolume(length);
Console.WriteLine("The volume of the Cube is {0:0.00}", volume);
break;
case 2:
Console.Write("Enter the radius of the cylinder: ");
radius = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the height of the cylinder: ");
height = Convert.ToDouble(Console.ReadLine());
volume = vol.cylinderVolume(height, radius);
Console.WriteLine("The volume of the cylinder is {0:0.00}", volume);
break;
case 3:
Console.Write("Enter the radius of the sphere: ");
radius = Convert.ToDouble(Console.ReadLine());
volume = vol.sphereVolume(radius);
Console.WriteLine("The volume of the sphere is {0:0.00}", volume);
break;
default:
break;
}
Console.WriteLine();
}
}