0

Hi,
I am trying to write the syntax using a FOR loop to sum numbers base on user input from a console apps. The user enters the total amount numbers to add 2 for eg then the actual numbers to add 4 and then 4 for eg.

so the using will enter the amount of numbers to add wNumber
then the first number to add yNumber
then the next mumber zNumber

ynumber+xNumber

display the result=

any suggestions on how i can approach this please?

2
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by 3Dees
0

Below is the code for what you are trying to do:

Dim numNumbers As Integer
        Dim total As Double
        numNumbers = InputBox("Please enter the number of numbers you would like to add", "Number of Numbers")

        Dim counter As Integer
        For counter = 1 To numNumbers
            total = total + InputBox("Please enter number " & counter, "Number " & counter)
        Next

        MsgBox("The total is " & total, MsgBoxStyle.OkOnly, "Total")

This code uses InputBoxes for input and MsgBoxes for output. Also, this code has no error handling; therefore, if someone types something other than a number, then there is an error. The key to this is to not have the program store each number individually but only the total; once the number is added to the total, there is no need to remember the number.

0

Thanks Timo,
I will try and transfer this code to work in a console application.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.