首页 \ 问答 \ 长度计算器英尺和英寸(Length calculator feet and inches)

长度计算器英尺和英寸(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
更新时间:2022-06-25 18:06

最满意答案

在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.
  • 在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 ...
  • 由于您将定义放在头文件中,因此会出现多重定义错误。 因为两个源文件都包含头文件,所以这两个地方都会定义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不是原始类型; 它包含在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中显示,它会告诉你为什 ...
  • 你不会收到错误,只是一个警告。 这适用于你如何声明你的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 ...
  • 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 ...
  • 如果你定义 const some_type x = some_value; 这意味着你无法修改x的值。 在没有volatile的情况下,编译器可以用some_value替换对x的some_value 。 如果你定义 const volatile some_type x = some_value; 然后你仍然无法修改x (至少不能使用名称x ),但编译器不能再认为它的值不能改变。 对x值的任何引用都必须实际从内存中加载其值; 它不能假设它将始终保持其初始值。 例如,可能存在一些特定于编译器的属性,它将x与 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)