问题描述
这是一个家庭作业问题。我会尽量保持最小化,所以不要让任何人为我做。我真的只是被困在一个小地方。
我必须从用户输入中找出最高的数字。
我给他们一个可供选择的菜单,我只能选择其中一个选项。
选择此选项时,我必须允许用户输入他/她想要输入的数量;然后我必须弄清楚哪个数字是最高的。
我已经在这个愚蠢的问题上工作了大约4天了。我只是坚持这个问题。我确定它很简单,但经过我的章节多次,尝试多种方式并没有让我通过它。
首先,我使用基本输入/输出显示菜单;然后我为所选的选择使用switch语句。一旦他们选择,我提供一个cin>>限制;,他们的数量; ;然后我问他们的第一个号码(cin>> num;);然后我开始一个计数器控制循环。一旦进入循环,我会问他们剩下的数字(cin>> num)。我很确定我应该使用if或if else语句,但到目前为止我一直在弄乱它。我不能一直得到最高的数字。我真正需要帮助的是找到最多的数字,输入5个数字。就像我说的那样,我自己完成了大部分的工作,只有这一件事让我退缩。我如何准确一致地找到正确的高数字?
这里是我试图得到最高数字的代码:
我有点喜欢。我尝试了几次而且我没有得到它。
我还是一个初学者。我是一级编程课。到目前为止,我一直很好。控制结构虽然容易,但同时也很难。 if,if ... else和switch语句对于我来说比循环更容易。
我想我会尝试再把它写在纸上,但我在纸上做的只是写代码对我来说应该是什么样的,但我会按照你提到的方式来做。
Strife
Hi,
This is a homework question. I will try to keep it minimal so not to have anyone do it for me. I am really just stuck on one small spot.
I have to figure out the highest number from a users input.
I give them a menu to choose from, and I am stuck on only one of the choices.
When this choice is picked I must allow the user to enter how many numbers he/she wants to enter; then I must figure out which number is the highest.
I have been working on this stupid problem for about 4 days now. I am just plain stuck on this problem. I''m sure it is something simple, but going through my chapter(s) multiple times, and trying multiple ways has not got me through it.
First, I use basic input/output to display the menu; then I use a switch statement for the choice selected. Once they pick, I provide a cin >> limit;, for their amount of numbers; ; then I ask for their first number(cin >> num;); then I begin a counter controlled for loop. Once in the loop I ask them for the rest of their numbers (cin >> num). I am pretty sure I am supposed to use an if or if else statement, but so far I keep messing it up. I cannot consistently get the highest number. All I really need help with is finding the highest number out of say, 5 numbers inputted. Like I said I have most of the work done on my own, just this one little thing is holding me back. How do I accurately and consistently find the correct high number?
here is the code I have trying to get the highest number:
well I kind of sort of did. I tried a couple of times and I am just not getting it.
I am still just a beginner. I am in the first level programming class. I have been doing fine up till this point. The control structures, although easy, are at the same time hard. The if, if...else, and switch statements were easier than the loops for me.
I guess I''ll try to get it on paper again, but all I do on paper is write what the code should look like to me, but I will do it the way you mentioned.
Strife
这篇关于需要帮助从用户输入中找到最高数量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!