如何获取用户的答案并使用它们来完成相应的操作? [英] How do I take the user's answers and use them to get the appropriate operation done?

查看:85
本文介绍了如何获取用户的答案并使用它们来完成相应的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个程序,接受用户的两个整数。然后它询问用户他想用这两个数字做什么。如果用户选择是



'A' - 添加两个数字



'B' - 减去第一个数字中的第二个数字



'C' - 将第一个数字乘以第二个数字



'D' - 将第一个数字除以第二个数字



'Q' - 结束操作







除非用户输入'Q'作为选择,否则您的程序应继续接受这两个数字和用户选择。

Write a program which accepts two integers from the user. Then it asks the user what he wants to do with those two numbers. If the user choice is

‘A’ – Add the two numbers

‘B’ – Subtract the second number from the first number

‘C’ – Multiply the first number by the second number

‘D’ – Divide the first number by the second number

‘Q’ – End the operation



Your program should continue to accept the two numbers and the user choice unless the user enters ‘Q’ as choice.

推荐答案

我们不做你的作业!

这是有原因的:这是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



建议:

- 阅读语言文档。

- 关注教程

- Google是你的朋友。
We do not do your homework !
It is set for a reason: It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Advice:
- read language documentation.
- Follow tutorials
- Google is your friend.


采用自上而下的方法设计你的应用伪代码。转换成您选择的语言留作练习。
Make a top-down approach to design your app in pseudo-code. Conversion into your language of choice is left as exercise.
function app()
{
   forever
   {
      a = read_number
      b = read_number
      c = read_action
      if (c == end) break
      if (c == add) write(a "+" b "=" a+b)
      if (c == sub) write(a "-" b "=" a-b)
      if (c == mul) write(a "*" b "=" a*b)
      if (c == div) write(a "/" b "=" a/b)
   }
}

问候

Andi

Regards
Andi


这篇关于如何获取用户的答案并使用它们来完成相应的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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