C# C Length Calculator错误/需要转换为double类型的对象
这是c控制台应用程序。我是编程新手。你们能帮我查一下这个吗?我错过了什么 这是程序说明: •长度计算器 •允许用户将厘米转换为英尺和英寸 •英尺和英寸到厘米 •用户将选择其中一种转换或选择取消此选项 •如果用户选择转换,他们将输入适当的值。 因此,对于英尺和英寸到厘米,用户将首先输入英尺数,然后输入英寸数。 • 如果是6英尺,英寸数可能是0 •显示结果后,询问用户是否希望进行另一次长度转换,他们可以回答“Y”或“N”或等效的小写字母 如果是,程序按上述步骤进行。如果否,则返回主菜单C# C Length Calculator错误/需要转换为double类型的对象,c#,console-application,calculator,C#,Console Application,Calculator,这是c控制台应用程序。我是编程新手。你们能帮我查一下这个吗?我错过了什么 这是程序说明: •长度计算器 •允许用户将厘米转换为英尺和英寸 •英尺和英寸到厘米 •用户将选择其中一种转换或选择取消此选项 •如果用户选择转换,他们将输入适当的值。 因此,对于英尺和英寸到厘米,用户将首先输入英尺数,然后输入英寸数。 • 如果是6英尺,英寸数可能是0 •显示结果后,询问用户是否希望进行另一次长度转换,他们可以回答“Y”或“N”或等效的小写字母 如果是,程序按上述步骤进行。如果否,则返回主菜单
public static double LengthCalculator() {
double Centimetres = 0.0, Feet = 0.0, Inches = 0.0;
string AnotherConversion;
string LengthCalculatorMenu;
int LengthCalculatorOption = 0;
do {
LengthCalculatorMenu=("\n1) Convert centimetres to feet and inches "
+ "\n2) Convert feet and inches to centimetres ");
Console.Write(LengthCalculatorMenu);
LengthCalculatorOption = int.Parse(Console.ReadLine());
Centimetres = double.Parse(Console.ReadLine());
if (LengthCalculatorOption == 1) {
Feet = (Centimetres / 2.54) / 12;
Inches = (Centimetres / 2.54) % (Feet * 12);
Console.WriteLine("Please Enter the Centimetres that you wish to convert to feet and inches");
Centimetres = double.Parse(Console.ReadLine());
Console.WriteLine("\nThe equivalent in feet and inches is {0:C} ft {1:C} ins", Feet, Inches);
Console.Write("\nWould you like to make an another conversion? \n\n(Enter Y to make an another conversion/Enter any other key to exit):");
AnotherConversion = Console.ReadLine();
} else if (LengthCalculatorOption == 2) {
Centimetres = ((Feet * 12) + Inches)*2.54;
Console.WriteLine("Please Enter the Feet");
Feet = double.Parse(Console.ReadLine());
Console.WriteLine("Please Enter the Inches");
Inches = double.Parse(Console.ReadLine());
Console.WriteLine("\nThe equivalent in centimetres is {0:C}", Centimetres);
Console.Write("\nWould you like to make an another conversion? \n\n(Enter Y to make an another conversion/Enter any other key to exit):");
AnotherConversion = Console.ReadLine();
} else {
Console.WriteLine("\n\a\t Invalid Option!Option Must be 1 or 2");
}
} while (AnotherConversion == "y" || AnotherConversion == "Y");
return;
} // end Length Calculator
这里的问题是LengthCalculator方法被声明为返回一个双精度值,但实际代码实际上并没有返回任何东西
return;
要解决此问题,您需要使该方法无效或返回一个双精度值。我的直觉是你想要一个空返回方法
public static void LengthCalculator()