Problem with random numbers

Hey everybodey i need your help to improve or to crrect this solution...
6.34 (Guess-the-Number Game) Write a program that plays the
game of “guess the number” as follows: Your program chooses the
number to be guessed by selecting an integer at random in the
range 1 to 1000. The program then displays the following:
The player then types a first guess. The program responds with
one of the following:
If the player’s guess is incorrect, your program should loop until
the player finally gets the number right. Your program should keep
telling the player or to help the player “zero in”
on the correct answer.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//Ejercicio6_38
//LuciusFernatore
//21 / 07 /2019

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

#include <cstdlib>

using std::srand;
using std::rand;

#include <ctime>

using std::time;



void guestTheNumber();

int main(int argc, char** argv)
{
	
	
	guestTheNumber();
	
	
	return 0;
}

void guestTheNumber()
{
	int givenNumber;
	int guessedNumber;
	bool flag = true;
	char verification;
	
	srand(time(0));
	
	givenNumber = 1 + rand() % 10;
	
	cout << "Guess the number between  1 to 1000... ";
	cin >> guessedNumber;
	
	   
	while(flag == true)
	{
		if(givenNumber == guessedNumber)
	   {
	   		cout << "Niceeoo you got that little puppy!" << endl;
	   		cout << "Would you like to play (Y or N)?" << endl;
	   		cin >> verification;
	   		
	   		switch(verification)
			{
			   	   case 'Y': givenNumber = 1 + rand() % 10;
				   	   break;
				   case 'y': givenNumber = 1 + rand() % 10;
				   	   break;   
 		           case 'N': flag = false;
				   	   break;
                   case 'n': flag = false;
				   	   break;  
			   	   default:
				   	   break;
			}
	   }
	   else
	   {
		   if(guessedNumber > givenNumber)
		   {
		   		cout << "Too high. Try again." << endl;
		   		cout << "Another try..." << endl;
				cin >> guessedNumber;
		   }
		   else
		   {
			   cout << "Too low. Try again." << endl;
			   cout << "Another try..." << endl;
               cin >> guessedNumber;
		   }
	   }	
	}
		
}
Guessing a random number between 1 and 100, using C++ random number generation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <random>

int main()
{
   std::cout << "Welcome to the number guessing game!!!\n";
   std::cout << "I have picked a number between 1 and 100.\n\n";

   // create a random device
   std::random_device rd;

   // set a distribution range (1 - 100)
   std::uniform_int_distribution<int> dist(1, 100);

   // pick and store the random number
   unsigned numPicked = dist(rd);

   unsigned guess    = 0; // stores the number the user guessed
   unsigned guessNum = 0; // stores the number of guesses

   for (guessNum = 0; guess != numPicked; guessNum++)
   {
      std::cout << "What would you like to guess? ";
      std::cin >> guess;

      if (guess < numPicked)
      {
         std::cout << "\nYou guessed too low!!!\n\n";
      }
      else if (guess > numPicked)
      {
         std::cout << "\nYou guessed too high!!!\n\n";
      }
   }
   std::cout << "\nYou guessed it!!!\n"
             << "It took you " << guessNum << " guesses.\n";
}
Welcome to the number guessing game!!!
I have picked a number between 1 and 100.

What would you like to guess? 50

You guessed too low!!!

What would you like to guess? 75

You guessed too low!!!

What would you like to guess? 90

You guessed too high!!!

What would you like to guess? 85

You guessed too high!!!

What would you like to guess? 80

You guessed too low!!!

What would you like to guess? 82

You guessed it!!!
It took you 6 guesses.
Topic archived. No new replies allowed.