计算用户输入的2个数字的结果 [英] Calculate the result of 2 numbers that the user entered
本文介绍了计算用户输入的2个数字的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在本练习中,写一个有理数的计算器,要求
用户输入两个有理数:
a / b + c / d
并产生结果:
(ad + bc)/ bd
解决方案
你有这个问题的哪一部分?
问用户什么?从用户那里检索一些东西?或产生结果?
- 您已经知道该怎么做在这里,因为你发布了它...
-Frinny
感谢Frinny回复但问题是什么时候更多来自2号?
我不确定你在问什么。
但我认为你可能会被困在根据十进制数得到分数用户输入。
假设用户输入0.36
作为第一个数字
- 设x = 0.36
- 计算小数点后的数字
- 在这种情况下,有2个。
- 将两边乘以100,因为我们需要将小数点移动2个位置。
- 我们得到100x = 36
- 解决x ...
- 在这种情况下x = 36/100。
假设用户已输入0.8744
作为第二个数字
- 设x = 0.8744
- 计算小数点后的数字
- 在这种情况下,有4个。
- 将两边乘以10000,因为我们需要将小数点移动4个位置。
- 我们得到10000x = 8744
- 解决x ...
- 在这种情况下x = 8744/10000。
所以,a = 36
和b = 100
。
并且,c = 8744
和d = 10000
。
-Frinny
In this exercise, write a rational number calculator that ask the
user to enter two rational number:
a/b + c/d
and produce the result:
(ad+bc)/bd
解决方案
What part of this this are you having problems with?
Asking the user something?Retrieving something from the user?
- use the printf method, or the cout method
Or producing the result?
- use the scanf method, or the cin method
- you already know what to do here because you posted it...
-Frinny
thanks Frinny to reply but the problem when is more from 2 Number??
I''m not sure what you''re asking.
But I think you might be stuck on getting the fraction based on the decimal number that the user entered.
Let''s say the user entered0.36
as the first number
- Let x = 0.36
- Count how many numbers there are after the decimal point
- In this case, there are 2.
- Multiply both sides by 100, because we need to move the decimal point 2 positions.
- We get 100x = 36
- Solve for x...
- In this case x = 36/100.
Let''s say the user entered0.8744
as the second number
- Let x = 0.8744
- Count how many numbers there are after the decimal point
- In this case, there are 4.
- Multiply both sides by 10000, because we need to move the decimal point 4 positions.
- We get 10000x = 8744
- Solve for x...
- In this case x = 8744/10000.
So,a=36
andb=100
.
And,c=8744
andd=10000
.
-Frinny
这篇关于计算用户输入的2个数字的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文