本文介绍了当用户输入“-1”时,如何将所有用户输入相加?在VB控制台内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要做的是让用户输入一个小于30的随机数,它会一直循环,直到用户键入-1,然后将所有输入加起来,然后是console.WriteLine(??)总。我还在尝试学习While循环,所以如果它是在一个while循环中完成的话会非常感激。
What I'm trying to do is get the user to input a random number less than 30 and it keeps looping until the user types "-1" then adds up all the inputs and it console.WriteLine(??) the total. I'm still trying to learn While Loops so it would be much appreciated if it was done in a while loop.
Module Module1
Sub Main()
Dim testing As Integer
Dim WhileCounter As Integer = Console.ReadLine()
While WhileCounter < 30
Console.WriteLine("Enter a number: ")
testing = Console.ReadLine()
If testing = "-1" Then
Console.WriteLine()
Exit While
End If
End While
Console.Read()
End Sub
End Module
我的尝试:
我尝试了一些基本的东西,比如测试+1,但只加1到-1然后我尝试了WhileCounter + Testing。但我无法找到我必须做的事情。
What I have tried:
What I have try some basic things like testing +1 but that only adds 1 to -1 then I've tried WhileCounter + Testing. But I cant find out what I have to do.
推荐答案
这篇关于当用户输入“-1”时,如何将所有用户输入相加?在VB控制台内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!