Hi I am trying to generate a random number between 1 - 100 using the example on this site. It works...sort of, except the number is never between my given range.
try this instead, it is my preferred method of generating a random number, although I've simplified the general structure of it for you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//your includes
int randomize(int max = 99, int min = 1)
{
// don't forget to seed once in main.
max++;
max -= min;
return (rand() % max + min);
}
int main()
{
//blah blah blah
distance = randomize(250, 200);
//blah blah blah
}
I may have too. I was recommended this version because it was free from MS. I may just start a new project and see if that fixes it first.
Thanks for your help
Ok ill admit im a total noob but something funny is up. Possibly my skills.
Long Double , I copied and pasted your code over my existing code, rebuilt the file and went to debug. I am still getting my golf info asking me for input. Which it again gave me 300 as the number.
Do I assume I need to compile the program another way?
++i just adds one to i, \n simply means end the line, so that you don't get all the numbers showing on a single line (at least until it wraps around the console window)