So now please tell me that is srand (time (0)) and srand (time (NULL)) the same? |
Yes they are the same. You can also write srand(time(nullptr)).
And what does this error mean? "rand () cannot be used as a function" |
You could get this error if you declare a local variable named rand. When you later try to call rand it will think you mean the variable and not the function. Calling a variable is of course not possible. To avoid this problem you can name the variable something else and/or write std::rand().
Also Peter87 said to use srand () in the start of program. Will it then give unique random numbers between 50 and 100 every time the loop runs or the game starts? |
Yes, but there is no guarantee the values will be unique. It is possible to get the same values again by chance.
srand is used to initialize the starting state of the random number generator. If you pass a fixed value to srand you will always get the same sequence of numbers from rand(). That is why we pass time(0) to srand so that we get a different sequence of numbers from rand each time we run the program.
Note that time(0) usually returns the time in seconds so if you run your program twice within the same second you will get the same sequence of numbers from rand(). This is often not a big deal because we normally don't run programs as often as that.
You never use the ex variable that is defined on line 10.
The loop runs as long as the loop variable ex is greater than 5. This is never the case so the loop never runs.
Im using codepad.org. Is it a good site? |
What do you use it for? I strongly recommend you install a C++ compiler on your own computer and use it when writing your programs. codepad.org was a good site for sharing small code snippets with other people but it looks like the C++ compiler is a bit outdated and doesn't support any of the C++11/C++14 features.