my question is, for the functions on choosing random numbers in a specific range, what should i do to make the cout one by one?
As in, like the function given above, it gives the whole 20 outputs at once, but what i would like to do is to get the output one by one, how could i do that?
thank you
one way to do this is to use the getch(); you can put it in the for loop right after the cout command. this will have the computer pause after each display of the number, pressing any key will make the computer continue. (you will also have to include #include <conio> to run the getch(); function.)
for example:
#include <iostream>
#include <conio>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
srand((unsigned)time(0));
int random_integer;
int lowest=1, highest=10;
int range=(highest-lowest)+1;
for(int index=0; index<20; index++){
random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0));
cout << random_integer << endl;
getch();
}
}
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Offline 84 posts
since Feb 2005