Taking an example from the program above, I’d like to clarify a question I’ve been having.
c++
So, with this program, it should supply a random number always different when run, right? Only 1, so I’d have to copy lines 8-14 again if I wanted a different random number?
Btw, I’m trying to get a “random” number from 1-100.
I’d appreciate any help.
c++
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
srand((unsigned)time(0));
int rn;
int lowest=1, highest=100;
int range=(highest-lowest)+1;
for(int index=0; index<20; index++){
rn=lowest+int(range*rand()/(RAND_MAX + 1.0));
}
if (rn<50)
{
cout<<”A random number is under 50”;
cout<<"("<<rn<<")";
}
So, with this program, it should supply a random number always different when run, right? Only 1, so I’d have to copy lines 8-14 again if I wanted a different random number?
Btw, I’m trying to get a “random” number from 1-100.
I’d appreciate any help.