Random number guessing game visual c#




















I am making a random number guessing game which the computer thinks of a number between It then asks you what it is and tells you if you are right or wrong. However, whenever I debug, it says that it is higher or lower than the actual random number for some reason.

Plus, it says two of those statements at once. Also, I'm not sure how to say how many guesses the person has taken. Here is my unsuccessful code. You're using a lot of unneeded iteration. The while statement takes a Boolean condition just like an IF statement. As others have said, you are misusing while where if is really neeeded. Generates a random number between 1 and 9 including 1 and 9. Ask the user the user to get the number, then tell them whether they guessed too low or too high, or exactly right.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 9 years, 11 months ago. Active 3 months ago. Viewed 51k times. WriteLine "I am thinking of a number between Can you guess what it is? ToInt32 Console. Can you guess what it is" ; Console.

WriteLine "Well done! Olivier Jacot-Descombes You have some whiles where you probably need ifs. In the above code, you see that we are first creating 2 variables, allowedTries and numberOfTries. We set the allowedTries variable to 5 and the numberOfTries variable to 0. Inside the while loop, we are first getting the guess from the user and assigning the guess to a variable guess.

Then we are incrementing the numberOfTries variable by 1. This is evaluated to be the number of tries the user has left. Now when we run the application, we will be able to guess a random number between 1 and until we get it correct or we run out of tries.

You have a working number guessing game. You can now play this game over and over for hours of fun. Not really, but I hope you enjoyed creating it as much as I did. Remember I am always learning, so if you see a mistake or know a better way of doing something I have shown here, please let me and others know in the comments below. Thanks for reading. You must be logged in to post a comment.

Facebook 0 Tweet 0 Pin 0. Do you need your password? Submit your solution! When answering a question please: Read the question carefully. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.

If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid. Related Questions. C guess random number game. The computer guess my number game problem. What is wrong with this letter guessing code? Help on simple guess game in VB.

Having difficulty with random object in C. Game in C - problem to receive 5 unique random numbers. Problem with randomize numbers. I want to record the user guess and show them a "letters guessed" array. Below is the code for my hangman game. Create a word guessing game. Layout: fixed fluid.



0コメント

  • 1000 / 1000