c++ rando number generator help

Write your question here.
hello , i am a beginner to c++ and new to this forum and i need help with this code.
i am trying to make a random number generator with a for loop
but there is something wrong with the code so i need help writing it properly
and i want to know what is wrong with the code.
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
  #include <iostream>
  #include <cstdlib>
  #include <ctime>

using namespace std;
int main ()
{
  int numpicked = 0;//stores the number the user guesses
  int guessnum;//stores the number of tries 
  int numgenerated;//the generated number

cout<<"welcome ! i have picked a number between 1 and 100";
srand ((int)time(NULL));
numgenerated = rand() % 100+1;

for (guessnum=0 ; guessnum != numpicked ; guessnum++)
{
cout<<"what would you like to guess? \n";
cin>>numpicked;

if(numpicked < numgenerated)//checks if the number picked is low

  cout<<"too low \n";

else if (numpicked > numgenerated)//checks if the number picked is high

  cout<<"too high \n";

}
cout<<"you guessed it! it took you "<<guessnum<<" guesses \n";

return 0;
}
 
Last edited on
change guessnum != numpicked of the for loop in line 16 to numgenerated != numpicked
thank you @shadowCODE it worked perfectly .
it would be good if i could have you kik or whatsapp :)
Topic archived. No new replies allowed.