kbum
09-08-2003, 01:01 PM
In this little program from my book, I didn't understand how
(1+rand()%6);
works. Can someone explain it to me please?
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
for(int counter=1;counter<=20;counter++)
{
cout << setw(10) << (1+rand()%6);
if(counter % 5 == 0)
cout << endl;
}
return 0;
}
(1+rand()%6);
works. Can someone explain it to me please?
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
for(int counter=1;counter<=20;counter++)
{
cout << setw(10) << (1+rand()%6);
if(counter % 5 == 0)
cout << endl;
}
return 0;
}