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.
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace 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";
elseif (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;
}