虽然循环(我认为)...... [英] While Loops (I think)...

查看:68
本文介绍了虽然循环(我认为)......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好(这里总VB.NET初学者),

我正在阅读SAMS在21天内自学VB.NET书,来了一个我无法开始工作的
。练习要求你创建一个游戏,让用户猜出一个1-100的数字,然后你告诉用户更低的数字。或更高或更高当他们输入他们的猜测时,他们会猜到正确的数字,然后你会告诉

用户正确。我尝试使用While循环,它是有点的。工作,

但是过了一段时间(没有双关语意)输入数字(猜测),它说b / b
表示正确不正确的答案。


这一章讨论了不同类型的循环等等,

和我猜他们希望我们使用一段时间循环为此

练习。如果有人有这本书,那就是在第二天结束时(页面

101)。


如果您有任何建议请告诉我有。


非常感谢。

霍华德

Hello everyone (total VB.NET beginner here),
I''m reading the "SAMS Teach Yourself VB.NET In 21 Days" book, and came
across an exercise that I can''t get to work. The exercise asks that
you create a game that makes the user guess a number from 1-100, and
you tell the user "lower" or "higher" as they input their guesses,
until they guess the correct number, at which point you then tell the
user "Correct". I tried using the While Loop, and it "sort of" worked,
but after a while (no pun intended) of inputting numbers (guesses), it
said "Correct" to incorrect answers.

The chapter was discussing different types of loops among other things,
and I''m guessing that they want us to use a While Loop for this
exercise. If anyone has the book, it''s at the end of day two (page
101).

Please let me know of any suggestions you may have.

Thank you very much.
Howard

推荐答案

嗨霍华德,


" Howard" <豪********** @ gmail.com> schrieb:
Hi Howard,

"Howard" <ho**********@gmail.com> schrieb:
我正在阅读SAMS在21天内自学VB.NET书,来了一个我无法工作的练习。练习要求您创建一个游戏,让用户猜出1-100的数字,并告诉用户更低的数字。或更高或更高当他们输入他们的猜测时,直到他们猜出正确的数字,然后你会告诉
用户正确。我尝试使用While循环,它是有点的。工作,
但是过了一会儿(没有双关语)输入数字(猜测),它说正确。不正确的答案。

本章讨论了不同类型的循环,
我猜他们希望我们使用While循环来进行这个练习。如果有人有这本书,那就是第二天结束时(页面
101)。
I''m reading the "SAMS Teach Yourself VB.NET In 21 Days" book, and came
across an exercise that I can''t get to work. The exercise asks that
you create a game that makes the user guess a number from 1-100, and
you tell the user "lower" or "higher" as they input their guesses,
until they guess the correct number, at which point you then tell the
user "Correct". I tried using the While Loop, and it "sort of" worked,
but after a while (no pun intended) of inputting numbers (guesses), it
said "Correct" to incorrect answers.

The chapter was discussing different types of loops among other things,
and I''m guessing that they want us to use a While Loop for this
exercise. If anyone has the book, it''s at the end of day two (page
101).




我没有这本书,但是你可以在这里发布你的代码的相关部分

,让其他人看到问题所在。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http://classicvb.org/请愿/>



I do not have the book, but you could post relevant parts of your code here
to enable other people to see where the problem lies.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


感谢您的帮助,

这里是我尝试使用的代码让锻炼渲染:


模块模块1

Sub Main()

Console.WriteLine(" Pick)数字从1到100)

Dim StrInput As Integer = Console.ReadLine()


While(StrInput<"" 27")

Console.WriteLine(" higher")

StrInput = Console.ReadLine()

结束时

虽然( StrInput>" 27")

Console.WriteLine (lower)

StrInput = Console.ReadLine()

结束时

Console.WriteLine(" Correct!")

StrInput = Console.ReadLine()


结束子


结束模块

再次感谢,

Howard


***通过Developersdex发送 http://www.developersdex.com ***
Thank you for the help,
Here''s the code that I used in an attempt to make the exercise render:

Module Module1

Sub Main()
Console.WriteLine("Pick a number from 1 to 100")
Dim StrInput As Integer = Console.ReadLine()

While (StrInput < "27")
Console.WriteLine("higher")
StrInput = Console.ReadLine()
End While
While (StrInput > "27")
Console.WriteLine("lower")
StrInput = Console.ReadLine()
End While
Console.WriteLine("Correct!")
StrInput = Console.ReadLine()

End Sub

End Module

Thanks again,
Howard

*** Sent via Developersdex http://www.developersdex.com ***


2005年12月18日


嗨霍华德,问题在于代码的设置方式。一旦输入高于27的

值,它就会向下移动到While StrInput> 27,因此如果它低于27,则永远不会再次检查....所以如果你在检查是否输入后输入任何值

低于27价值更高,然后

你会越过第二个并获得正确的信息。


来证明:

- 以2个不正确的值达到正确:

输入28+

输入小于27


您需要做的是检查它是否更低/更高/更正每次a / $
值被输入,而不仅仅是检查一次和如果它通过,那么永远不要检查

新值。


这可以通过使用While Incorrect(作为布尔)类型来实现

结构:


Dim SuccessfulGuess为boolean = false

Dim StrInput为整数


当SuccessfulGuess = false时


StrInput = Console.Readline


如果StrInput< 27然后

console.writeline(更高)


ElseIf StrInput> 27然后

console.writeline(" lower")

ElseIf StrInput = 27

console.writeline("正确) !)

SuccessfulGuess = true

结束如果


结束时

告诉我如果你有疑问! :-)


-


Joseph Bittman

微软认证解决方案开发商

Microsoft最有价值专业人士 - DPM

博客/网站: http://71.39.42.23/


" Howard Portney" <豪********** @ gmail.com>在消息中写道

新闻:OB ************** @ tk2msftngp13.phx.gbl ...
December 18, 2005

Hi Howard, the issue is the way the code is set up. As soon as you enter a
value higher than 27, it moves down to While StrInput > 27, and therefore is
never checked again if it is lower than 27.... so if you input any value
lower than 27 after it moves to checking whether the value is higher, then
you will move past the 2nd while and get the Correct message.

To demonstrate:
-Reach Correct in 2 incorrect values:
input 28+
input less than 27
CORRECT! :) lol

What you need to do is check whether it is lower/higher/correct EACH time a
value is inputed, not just check once and if it passes then never check the
new values.

This can be accomplished by using a While Incorrect(as boolean) type
structure:

Dim SuccessfulGuess as boolean = false
Dim StrInput as integer

While SuccessfulGuess = false

StrInput = Console.Readline

if StrInput < 27 then
console.writeline("higher")

ElseIf StrInput > 27 then
console.writeline("lower")

ElseIf StrInput = 27
console.writeline("Correct!")
SuccessfulGuess = true
End If

end while
Let me know if you have questions! :-)

--

Joseph Bittman
Microsoft Certified Solution Developer
Microsoft Most Valuable Professional -- DPM

Blog/Web Site: http://71.39.42.23/

"Howard Portney" <ho**********@gmail.com> wrote in message
news:OB**************@tk2msftngp13.phx.gbl...
谢谢你的帮助,
这是我用来尝试进行练习的代码:

模块模块1

子主()
控制台.WriteLine(从1到100选择一个数字)
Dim StrInput As Integer = Console.ReadLine()

while(StrInput<"" 27")
Console.WriteLine(更高)
StrInput = Console.ReadLine()
结束时
While(StrInput>" 27")
Console.WriteLine(") strInput = Console.ReadLine()
结束时
Console.WriteLine(正确!)
StrInput = Console.ReadLine()

End Sub

结束模块

再次感谢,
Howard

***通过Developersdex发送 http://www.developersdex.com ***
Thank you for the help,
Here''s the code that I used in an attempt to make the exercise render:

Module Module1

Sub Main()
Console.WriteLine("Pick a number from 1 to 100")
Dim StrInput As Integer = Console.ReadLine()

While (StrInput < "27")
Console.WriteLine("higher")
StrInput = Console.ReadLine()
End While
While (StrInput > "27")
Console.WriteLine("lower")
StrInput = Console.ReadLine()
End While
Console.WriteLine("Correct!")
StrInput = Console.ReadLine()

End Sub

End Module

Thanks again,
Howard

*** Sent via Developersdex http://www.developersdex.com ***



这篇关于虽然循环(我认为)......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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