#Number Guessing game problem, help please.

1 messages · Page 1 of 1 (latest)

main beacon
#

Hello I am working on an assignment for extra credit and I have to create a number guessing game between 5-25 I have completed my code but I see that it bugs or if inserted something wrong, can someone please help me.
Here's my code:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int num,
guess,
tries = 0;
srand(time(0));
num = rand() % 25 + 5;
cout << "Guess My Number Game\n\n";
do
{cout << "Enter a guess between 5 and 25 : ";
cin >> guess;
tries++;
if (guess > num)
cout << "Too high. Try again.";
else if (guess < num)
cout << "Too low, Try again." ;
else
cout << "Congratulations. You figured out my number in " << tries << " guesses!\n";}
while (guess != num);

return 0;
}
hushed jacinthBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

main beacon
#

If you haven't notice, I inserted 25 when running the program and it showed it was too low.

primal trench
#

consider rand() % 25 + 5

#

what happpens if rand() returns 24 for example

main beacon
#

it still says sometimes it is to low

steady gazelle
#

What is the maximum value of rand() % 24?

main beacon
steady gazelle
#

I'm not talking about the assignment, just that: rand() % 24

#

Or more generally, given any integer N, what is the maximum value of rand() % N?