简单的任务 [英] Simple assignment

查看:86
本文介绍了简单的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的c ++类中到目前为止第8章是while循环for循环if / else if和嵌套ifs字符数组以及之前的所有基础。

现在我的程序在循环中本书的一部分是要求用户猜测1到100之间的数字。我的第一个猜测必须是50,所以我写了一个案例陈述,询问他是否数字50或者是否太高或太低。然后我班上的同龄人说,在他们的案例陈述中放置If语句以继续缩小它你将如何做到这一点。我不知道怎么去编码,有人可以带领我朝着正确的方向前进。几分钟之前的其他人告诉我,然后在25点的中点将其缩小,如果它更低,或者如果更高,则将其缩小到两个但是这对我没有任何意义。到目前为止,我所写的只是案例陈述和

案例1:

number;我不知道如何在if语句中添加if语句以及if语句中应该包含什么。哦,请记住,如果有人知道任何更短的方法,这将是很好的,因为我知道我需要最终在某处增加。我可以把这个程序代码的基础知识显示给我,我完全迷失了。

In my c++ class so far were up to chapter 8 which is do while loops for loops if/else if and nested ifs character arrays and everything basic before that.
Now my program in the loop section of the book is asking the user to guess a number between 1 and 100. My first guess must be 50 so I have written a case statement asking him if the number 50 or if its too high or too low . then my peers in class say that put If statements in their case statement to keep narrowing it down how would you go about doing this. I don''t know how to go around coding this can someone please lead me in the right direction . Someone else a few minutes ago told me to then narrow it by the midpoint of 25 if its lower or 75 if higher and diving by two but this makes no sence to me. All I have written so far is the case statement and for
Case 1:
number; I have no idea how to put an if statement in a case and what I should have in the if statement. Oh keep in mind if anyone knows any shorter ways to do this it would be nice since I know I''ll need to increment eventually somewhere. Can I please have the basics of the code for this program shown to me i''m totally lost.

推荐答案

你试图实现一个二进制搜索算法。?二分搜索是一种众所周知且有效的算法。


去年我必须做那个确切的工作。我记得它听起来更难了。


这是一个非常着名的算法,我确定谷歌的东西是什么样的?二进制搜索算法,?你在路上是对的!


哦!而且我认为案例陈述不是你所需要的。你需要while / do循环使用if语句。
You?re trying to implement a ?binary search algorithm.? A binary search is a very well known and efficient algorithm.

I had to do that exact assignment last year. I remember it was harder then it sounded.

It?s a very well known algorithm, I?m sure if google something like ?binary search algorithm,? you?ll be right on your way!

Oh! And I don?t think a case statement is what you need. Your going to need while/do loops with if statements.


while(theyInput!=" Yes")

{


if(Yes)

{

cout<< 很棒!;

休息;

}

if(更高)

{

lowerRange = guess;

guess =(upperRange - lowerRange)/ 2;

guess + = lowerRange;

}

else if(" Lower")

{

upperRange = guess;

guess =( upperRange - lowerRange)/ 2;

guess + = lowerRange;

}

返回0;

}


我是在正确的轨道上。除了初始化和第一个cout语句之外,我还缺少什么?
while( theirInput != "Yes" )
{

if ( "Yes" )
{
cout << "Great!";
break;
}
if( "Higher" )
{
lowerRange = guess;
guess = ( upperRange - lowerRange ) / 2;
guess += lowerRange;
}
else if( "Lower" )
{
upperRange = guess;
guess = ( upperRange - lowerRange ) / 2;
guess += lowerRange;
}
return 0;
}

Am I on the right track. What more am i missing besides the initilizing and the first cout statements?


我觉得做任务有点不好但是...我想让你看两行;我给他们贴了标签?第1行?和?Line2?


你需要弄清楚我为什么这样做。我可以告诉你,但是我也是学生,我需要做自己该死的作业LOL

I feel a little bad for doing your assignment but... I want you to look at two lines; I labeled them ?Line 1? and ?Line2?

You need to figure out why I did it that way. I could just tell you, but I?m a student too and I need to do my own damn homework LOL


展开 | 选择 | 换行 | 行号


这篇关于简单的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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