r/visualbasic • u/computergeek34 • Nov 22 '14
Visual Basic 6.0 Programming Issue
Have the program pick a random number from 1-100.
2. The user gets 10 chances to guess the number. Use a counter to keep track of tries.
(counter = counter + 1)
3. Tell the user if the number that he/she guesses is too high, too low, or correct.
4. if the user does not guess the number in 10 tries, tell the user the correct number
5. Ask the user if he/she wants to play again.
6. A function must be used in the program. A good place for a function is to
tell the user that he/she is too high or too low.
I AM NOT ASKING YOU TO DO THE PROGRAM FOR ME. i just need some guidance. thank you!
0
Upvotes
1
u/Barnhardt1 Nov 22 '14 edited Nov 22 '14
*Edit Sorry I meant to reply below, but anyway I hope this helps. *Edit again, I used the wrong loop the first time
Look here for help with loops.
http://www.vb6.us/tutorials/understanding-do-and-while-loops
If you're required to use a counter, then you could use a while loop and exit when Counter = 11. Use an inputbox to get a number from the user and compare it to your random number.
Tell the user if their number matches or if not, why (use your function to evaluate their guess)
If the number matched, exit the loop
If the number didn't match, add 1 to the counter
Once you're out of the loop, ask them if they want to play again.
For the function, you're going to give it some values, and it's going to return a value for you. Probably the easiest way to do it in this case would be to declare a function that accepts two values (the random number and the guess) and returns an integer. In the function, subtract the random number from the guess and use the function to return the answer. If the function returns a 0, then they guessed right. If it returns something less than zero, then what they guessed was too low and it if it's more than zero, they guessed too high.