Users Online

· Guests Online: 42

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C++ Program to Emulate N Dice Roller

C++ Program to Emulate N Dice Roller

 

 

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.

  1. #include <iostream>
  2. #include <stdlib.h>
  3.  
  4. using namespace std;
  5.  
  6. int main(int argc, char **argv)
  7. {
  8.     cout << "Enter the number of dice: ";
  9.     int n;
  10.     cin >> n;
  11.     cout << "The values on dice are: ( ";
  12.     for (int i = 0; i < n; i++)
  13.         cout << (rand() % 6) + 1<<" ";
  14.     cout<<")";
  15. }

Output:

$ 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 )

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.72 seconds
10,820,449 unique visits