C++ Random number guessing game

后端 未结 5 1457
我寻月下人不归
我寻月下人不归 2021-01-28 06:50

I have to write a program that will run a random guessing game. The game is to be numbers from 1-100, the guesser gets 20 tries and at the end is supposed to be asked if they wo

5条回答
  •  醉话见心
    2021-01-28 07:21

    One problem that I see is that you are picking a new random number for each user guess. This is wrong.

    To fix this you should put the

    number=rand()%100+1;
    

    line before the do while loop that loops asking for guesses.

    A second problem is the condition on that loop is not correct. You should loop until number == guess not number > guess and put the both couts that tell the user if the guess is high or low inside the loop and increment your tries inside the loop as well.

    Also you probably want to have an outer do while() loop for the question that asks you to play again instead of this loop being after the loop that waits till the user gets the right number.

提交回复
热议问题