C#LengthCalculator错误/需要可转换为double的类型的对象

时间:2014-03-22 14:17:39

标签: c# console-application calculator

这是c#console app。我是编程的新手。你们能为我检查一下这是对的吗?我错过了什么??????

是节目描述:

•长度计算器

•允许用户将厘米转换为英尺和英寸

•英尺到英寸到厘米

•用户将选择其中一个转化,或选择取消此选项。

•如果用户选择转换,他们将输入适当的值。     因此,对于英尺和英寸到厘米,用户将首先输入英尺数,然后输入英寸数。 •     在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

1 个答案:

答案 0 :(得分:0)

这里的问题是方法LengthCalculator被声明为返回double值但实际代码实际上没有返回任何内容

return;

要解决此问题,您需要制作方法void或返回double值。我的预感是你想要一个void返回方法

public static void LengthCalculator()