以英寸和英尺为单位的测量距离 [英] measuring distance in inches and feets

查看:112
本文介绍了以英寸和英尺为单位的测量距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写程序,该程序应将两个距离相加并以英尺和英寸为单位显示结果.初始距离是在程序的开头设置的,应根据用户的输入进行修改.

i need to write program which should add two distances and display the result in feet and inches. The initial distance is set in the beginning of the program, which should be modified according to the input of the user.

推荐答案

首先将所有尺寸转换为英寸.以英寸为单位进行计算,然后显示转换回英尺和英寸.
Firstly convert all measurements to inches. Do the calculations as inches, then to display convert back to feet and inches.


请尝试以下操作:

Try this one:

private void button1_Click(object sender, EventArgs e)
{
   const int divider = 12;
 
   double distance1 = double.Parse(textBox1.Text);
   double distance2 = double.Parse(textBox2.Text);
 
   double totalInches = distance1 + distance2;
   double totalFeet = totalInches / divider;
   MessageBox.Show("Total in inches: " + totalInches.ToString() + "Total in feet: " + totalFeet.ToString());
}



希望您从这里得到逻辑.不再包含数据输入验证:)

顺便说一句,这里的输入是固定为 inches 的,您可以先尝试通过创建一个函数来将所有输入转换为英寸,该函数将转换后的值返回为等效的英寸.

问候,
爱德华



Hope you get the logic from here. Did not included data input validation anymore :)

BTW, input here is fixed for inches you can try converting all input to inches first by creating a function that will return the converted values as inches equivalent.

Regards,
Eduard


这篇关于以英寸和英尺为单位的测量距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆