长度计算器英尺和英寸(Length calculator feet and inches)
在我的if语句中“(LengthCalculatorOption == 1)”例如,我想将187.96cm转换为英尺,如6feet 2ins。 我怎么做? 因为在我目前的代码中,它会显示6.17feet并始终为0ins。 我不知道为什么。
static void Main(string[] args) { double Centimetres = 0.0, Feet = 0.0, Inches = 0.0; string AnotherConversion = null; string LengthCalculatorMenu; int LengthCalculatorOption; do{ LengthCalculatorMenu = ("Enter 1) Convert centimetres to feet and inches:" + "\nEnter 2) Convert feet and inches to centimetres:"); Console.Write(LengthCalculatorMenu); LengthCalculatorOption = int.Parse(Console.ReadLine()); if (LengthCalculatorOption == 1) { Console.WriteLine("Please Enter the Centimetres(cm) that you wish to convert to feet and inches"); Centimetres = double.Parse(Console.ReadLine()); Feet = (Centimetres / 2.54) / 12; Inches = (Centimetres / 2.54) - (Feet * 12); Centimetres = ((Feet * 12) + Inches) * 2.54; Console.WriteLine("\nThe equivalent in feet and inches is {0:C} ft {1:G} 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) { Console.WriteLine("Please Enter the Feet"); Feet = double.Parse(Console.ReadLine()); Console.WriteLine("Please Enter the Inches"); Inches = double.Parse(Console.ReadLine()); Centimetres = ((Feet * 12) + Inches) * 2.54; Console.WriteLine("\nThe equivalent in centimetres is {0:G}cm", 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");
in my if statement "(LengthCalculatorOption == 1)" For example I want 187.96cm convert to foot and inches such as 6feet 2ins. How do I do that? because in my current code, it will show 6.17feet and always 0ins. I have no idea why.
static void Main(string[] args) { double Centimetres = 0.0, Feet = 0.0, Inches = 0.0; string AnotherConversion = null; string LengthCalculatorMenu; int LengthCalculatorOption; do{ LengthCalculatorMenu = ("Enter 1) Convert centimetres to feet and inches:" + "\nEnter 2) Convert feet and inches to centimetres:"); Console.Write(LengthCalculatorMenu); LengthCalculatorOption = int.Parse(Console.ReadLine()); if (LengthCalculatorOption == 1) { Console.WriteLine("Please Enter the Centimetres(cm) that you wish to convert to feet and inches"); Centimetres = double.Parse(Console.ReadLine()); Feet = (Centimetres / 2.54) / 12; Inches = (Centimetres / 2.54) - (Feet * 12); Centimetres = ((Feet * 12) + Inches) * 2.54; Console.WriteLine("\nThe equivalent in feet and inches is {0:C} ft {1:G} 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) { Console.WriteLine("Please Enter the Feet"); Feet = double.Parse(Console.ReadLine()); Console.WriteLine("Please Enter the Inches"); Inches = double.Parse(Console.ReadLine()); Centimetres = ((Feet * 12) + Inches) * 2.54; Console.WriteLine("\nThe equivalent in centimetres is {0:G}cm", 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");
原文:https://stackoverflow.com/questions/22590406
最满意答案
在operator =函数中,inNode是常量。 函数
getID
不是常量,因此调用它会丢弃inNode的常量。 只需使getID const:luint getID() const { return this->ID; }
In your operator= function, inNode is constant. The function
getID
is not constant, so calling it is discarding the constness of inNode. Just make getID const:luint getID() const { return this->ID; }
相关问答
更多-
你有没有在你的Makefile中定义LINUX或WINDOWS定义? 尝试 gcc -dM -E - < /dev/null 这会打印所有预定义的宏。 这里是Windows宏 。 have you defined LINUX or WINDOWS define in your Makefile? try gcc -dM -E - < /dev/null this prints all the predefined macros. and here the windows macros.
-
它是一个指定符和限定符的列表:-)指定符是像void , char , struct Foo等等,并且限定符是像const和volatile这样的关键字。 有关定义,请参阅此C语法 。 在你的情况下, undefined_type还没有定义,所以解析器将它看作是一个标识符,而不是像预期的那样指定了一个限定符列表。 如果你要typedef ... undefined_type; 在它出现之前,那么undefined_type将成为一个说明符。 如果您认为使用上下文无关语法解析C,则编译器处理typedef的方 ...
-
尝试: struct _Nodo *solicita 。 Try: struct _Nodo *solicita.
-
c ++限定符错误(c++ qualifier error)[2022-12-19]
在operator =函数中,inNode是常量。 函数getID不是常量,因此调用它会丢弃inNode的常量。 只需使getID const: luint getID() const { return this->ID; } In your operator= function, inNode is constant. The function getID is not constant, so calling it is discarding the constness of inNode. Just ... -
C - 使用extern限定符(C - usage of extern qualifier)[2022-05-01]
由于您将定义放在头文件中,因此会出现多重定义错误。 因为两个源文件都包含头文件,所以这两个地方都会定义g ,因此会导致错误。 你想把声明放在头文件和定义在一个源文件中: 在header1.h中: extern int g; 在test.c中: int g = 10; 并没有在main.c中。 You get a multiple definition error because you put the definition in the header file. Because both source ... -
错误:标头结构中FILE之前的预期说明符限定符列表(Error : expected specifier qualifier list before FILE in header struct)[2023-06-05]
那是因为FILE不是原始类型; 它包含在stdio.h头文件中。 因此,您需要在文件中使用#include包含它。 That's because FILE is not a primitive type; it is contained in the stdio.h header. So you need to include it using #include within your file. -
当我对通过字符串属性创建的对象的类型感到困惑时,我使用这种技术。 在Excel的Visual Basic编辑器中,如果没有您希望以这种方式使用的现有模块,请创建一个新模块。 如果您在Project Explorer中选择模块并单击F4,则可以将模块名称更改为“Experiments”。 键入或复制: Option Explicit Sub TestA() End Sub 我总是用Option Explicit启动我的模块。 Look Option Explicit在VBA Help中显示,它会告诉你为什 ...
-
“无用类型限定符”错误(“useless type qualifier” error)[2023-08-25]
你不会收到错误,只是一个警告。 这适用于你如何声明你的struct cal :它本身不是易失性的; volatile只适用于具体的变量定义。 所以在static struct cal cal ,你的变量cal只是static ,但不是volatile 。 从这个意义上讲,正如警告所说, volatile声明是无用的。 You don't get an error, just a warning. And that applies to how you declare your struct cal: it ... -
在某些C ++编译器上使用restrict限定符的编译器错误(Compiler error using restrict qualifier on certain C++ compilers)[2022-10-21]
IBM的XL C / C ++编译器不支持您的构造,它也在其文档中说明 。 您不能相互指定受限制的指针。 你可以通过创建一个新的块作用域和一组新的指针来解决这个问题。 { int * restrict x; int * restrict y; x = y; /* undefined */ { int * restrict x1 = x; /* okay */ int * restrict y1 = y; /* okay */ x = y1; /* un ... -
C ++为什么存在“const volatile”类型限定符?(C++ Why does the “const volatile” type qualifier exist? [duplicate])[2023-11-16]
如果你定义 const some_type x = some_value; 这意味着你无法修改x的值。 在没有volatile的情况下,编译器可以用some_value替换对x的some_value 。 如果你定义 const volatile some_type x = some_value; 然后你仍然无法修改x (至少不能使用名称x ),但编译器不能再认为它的值不能改变。 对x值的任何引用都必须实际从内存中加载其值; 它不能假设它将始终保持其初始值。 例如,可能存在一些特定于编译器的属性,它将x与 ...