0

Hello . . I'm trying to get my random number generator to work but i'm having a tough time

here's what i've written so far

I can't seem to get the number generator to give me a truly random number . . . i'm sick of tooling with it and need a solution

Also . . .when i get it to work , it always generates the same number.

if I go through the game i've set up, and I guess the random number in 10 tries, it replays if you get it right . .but if you use up all your guesses, it just exits . . I can't seem to solve this problem either.

```
// C++ 1 Lab Final
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
void replay();
int random();
int game(int guess, int rad_num);
int seed = rand();
void main(){
int guess;
int rad_num = random();
cout<<"Guess a number between 1 and 100 ";
cin >> guess;
game(guess, rad_num);
cout <<"The random number is \n"<<rad_num<<endl;
}
random(){
srand(time(NULL)); // I need Help here generating a number
int i;
int rad_gen;
int rad_res;
for (i=0; i<rand() % 100;i++){
rad_gen = (rand());
rad_res = rad_gen % 100;
}
return rad_res;
}
game(int guess, int rad_num){
int guess_count;
for (guess_count=10; guess_count>0; --guess_count){
if (guess == rad_num){
cout<<"You guessed right. "<<endl;
replay();
}
else if (guess < rad_num){
cout<<"Too low \n"<<guess_count<<" guesses left."<<endl;
cout<<"guess again ";
cin>>guess;
}
else {
cout<<"Too high \n"<<guess_count<<" guesses left."<<endl;
cout<<"guess again ";
cin >> guess;
}
if (guess_count == 0)
cout <<"Sorry you used all your guesses \n "; // This doesn't work
replay();
}
}
return 0;
}
void replay(){
int play;
cout<<"Play again? 1 for yes, 2 for no \n";
cin >> play;
if (play == 1){
main();
}
else{
cout<<"Good Bye";
exit(0);
}
}
```

*Edited 5 Years Ago by Narue*: Added [CODE] tags