In: Computer Science
The code:
#include<iostream>
#include<time.h>
using namespace std;
int main() // main function
{
int r;
srand(time(0)); // initializing random number generator
cout << "The result of rolling an 8 sided die 5 times:" << endl;
for (int i=0; i<5; i++) // loop is executing 5 times
{
r = rand() % 8 + 1; // generate a random number
cout << r << " "; // showing the result
}
}
The code with output: