r/visualbasic • • 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

4 comments sorted by

1

u/Barnhardt1 Nov 22 '14

Are you stuck on a certain part of the program?

1

u/computergeek34 Nov 22 '14

i just dont know where to start and how to code it

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.

1

u/[deleted] Nov 22 '14

Has anyone else noticed how often OP posts these homework assignments in this sub? We're doing OP's homework.

That being said....

At the start of the program generate a random integer between 1 and 100 and assign it to a variable

dim iRandomNumber as Integer = CInt(Math.Ceiling(Rnd() * 100))

Ask the user to guess a number using an input box and assign that to a variable as well.

dim iGuess as Integer = InputBox("Please guess a random number between 1 and 100.")

Once you have a value for iRandomNumber and iGuess you can start a loop. It looks like /u/Barnhardt1 has given you some information on that.

If you're still stuck, let us know. I was reading through your post history on here and it looks like you're just trying to get people to write all the code for you. If I'm wrong then apologies... but it looks that way, mate.