The man who always smiles!  by Adnan Sharbaji
The man who always smiles! by Adnan Sharbaji

I moved forward to #WSQ06. I really enjoyed doing it. It was kind of a challenge but I think I am already developing more programming skills. I had to make a code that would choose a random number from 1 to 100 for the user to guess. My main problem was that when I ran it, the program would always choose number 8. I first asked to a friend of mine, who studies Sistems Engineering, but he could no help me. So I asked Ken. He told me that the problem was the seed. I found this webpage that gave me the last hint:

http://stackoverflow.com/questions/3693511/rand-seeding-with-time-problem

And now, here’s my code:

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int number,guess, count=0;
cout<<“I have a number between 1 and 100″<<endl;
srand((int)time(NULL));
number= rand() % 100 + 1;
cout<<“Try to guess the number:”;
cin>>guess;
count = count + 1;

while(guess != number){
if (guess>number)
cout<<“Too high”<<endl;
if (guess<number)
cout<<“Too low”<<endl;
cout<<“Try to guess the number:”;
cin>>guess;
count = count + 1;
}
cout<<“That’s it! you guessed right.”<<endl<<cout<<“The number of times it took you to guess is:”<<count<<endl;

return 0;
}

CC BY 4.0 Guess the number by Mferflores is licensed under a Creative Commons Attribution 4.0 International License.