C++ Program to Emulate N Dice Roller


Here is the code to emulate N dice roller. This can be done by generating random number between 1-6.

Algorithm

Begin
   Declare n
   Read n
   For i = 0 to n-1 do
      Generate sequence with rand() mod 6 + 1
      Print the sequence
   Done
End

Example Code

#include <iostream>
using namespace std;
int main(int argc, char **argv) {
   cout << "Enter the number of dice: ";
   int n;
   cin >> n;
   cout << "The values on dice are: ";
   for (int i = 0; i < n; i++)
      cout << (rand() % 6) + 1<<" ";
}

Output

Enter the number of dice: The values on dice are: 2 5 4 2 6 2 5

Updated on: 30-Jul-2019

811 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements