Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 52 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdlib>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. int rollDice();
  8.  
  9.  
  10. int main()
  11. {
  12.     srand(time(0));    
  13.     int RollNum;    // number of times to roll dice
  14.     int dicerollValues [5000];
  15.     float percentage[10] = {0}; // Array for percentages of numbers
  16.     int counter[11];
  17.     int i, a;
  18.     int value;
  19.     int rollsRemaining;
  20.    
  21.    
  22.    
  23.     //Ask how many times to roll dice
  24.     cout << "How many times will the dice roll?";
  25.     cin >> RollNum;
  26.     rollsRemaining == RollNum;
  27.     //Generate that number of random rolls
  28.     for (i=0; i <= RollNum; i++)
  29.     {
  30.         //Call Dice Roll function
  31.         dicerollValues[i] = rollDice();
  32.         for (value=2 ; value<=12 ; value++)
  33.         {
  34.             if (dicerollValues[i] == value)
  35.             counter[value-2]++;
  36.         }
  37.         i++;
  38.     }
  39.     // loop to calculate percentage of the time each value occurs
  40.     for (a= 0; a <12; a++)
  41.         percentage [a] = (counter[a]/((float)(RollNum)))* 100;
  42.  
  43.     //Display Results
  44.     cout << "The dice were rolled " << rollsRemaining << " times." << endl;
  45.     cout << "The value 2 came up " << counter [0] << " times or " << percentage[0] << "% of the time." << endl;
  46.     cout << "The value 3 came up " << counter [1] << " times or " << percentage[1] << "% of the time." << endl;
  47.     cout << "The value 4 came up " << counter [2] << " times or " << percentage[2] << "% of the time." << endl;
  48.     cout << "The value 5 came up " << counter [3] << " times or " << percentage[3] << "% of the time." << endl;
  49.     cout << "The value 6 came up " << counter [4] << " times or " << percentage[4] << "% of the time." << endl;
  50.     cout << "The value 7 came up " << counter [5] << " times or " << percentage[5] << "% of the time." << endl;
  51.     cout << "The value 8 came up " << counter [6] << " times or " << percentage[6] << "% of the time." << endl;
  52.     cout << "The value 9 came up " << counter [7] << " times or " << percentage[7] << "% of the time." << endl;
  53.     cout << "The value 10 came up " << counter [8] << " times or " << percentage[8] << "% of the time." << endl;
  54.     cout << "The value 11 came up " << counter [9] << " times or " << percentage[9] << "% of the time." << endl;
  55.     cout << "The value 12 came up " << counter [10] << " times or " << percentage[10] << "% of the time." << endl;
  56.    
  57.     return 0;
  58. }
  59.  
  60. int rollDice()
  61. {
  62.     int die1;
  63.     int die2;
  64.     int total;
  65.     die1 = rand( ) % 6 + 1;  
  66.     die2 = rand( ) % 6 + 1;
  67.     total = die1 + die2;
  68.     return total;
  69.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top