This is a C++ Program to emulate N-dice roller. This can be done by generating random number between 1-6.
Here is source code of the C++ Program to Emulate N Dice Roller. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
using namespace std;
int main(int argc, char **argv)
cout << "Enter the number of dice: ";
cin >> n;
cout << "The values on dice are: ( ";
for (int i = 0; i < n; i++)
cout << (rand() % 6) + 1<<" ";
$ g++ EmulateNDice.cpp $ a.out Enter the number of dice: 5 The values on dice are: ( 6 6 5 5 6 ) Enter the number of dice: 1 The values on dice are: ( 6 ) Enter the number of dice: 3 The values on dice are: ( 6 6 5 )
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.