Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What code would I use to have a user enter a number then have them randomly choo

ID: 3652414 • Letter: W

Question

What code would I use to have a user enter a number then have them randomly choose to enter that many different numbers. I want to then add those numbers up. An example I can come up with is say I give them the option of entering say any number between 2 and 5 and then they can randomly chose to enter that amount of numbers. If I chose the number 3 I can choose any three numbers and the coding will add those three numbers up. The coding will also tell the user to stop after entering 3 random numbers.

Explanation / Answer

'you'll need a do while loop and a for loop..something like this: Dim num As Integer Dim sum As Double = 0.0 Dim Cnt As Integer 'loop until number entered is between 2 and 5 Do While num < 2 Or num > 5 num = InputBox("Enter any number between 2 and 5", "Get number of Numbers", "2") Loop For Cnt = 1 To num sum += InputBox("Enter an number ", "Getting numbers for average") Next Cnt MessageBox.Show("The average is " + (sum / num).ToString, "Average", MessageBoxButtons.OK, MessageBoxIcon.None)
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote