fork(1) download
  1. #include <iostream>
  2. #include <time.h>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8. cout << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2);
  9. srand(time(NULL));
  10.  
  11. //6 faces, random, multiple rolls.
  12.  
  13. // Number of rolls. Faces of the dice.
  14.  
  15. int numRolls;
  16.  
  17. cout <<"How many times would you like to roll the dice? ";
  18. cin >> numRolls;
  19.  
  20. double diceOutcome[6]={0}; // 0-5, all set to 0.
  21.  
  22. for(int i=0; i<numRolls; i++){
  23. diceOutcome[rand()%6]++;//Rand is 0 indexed as well, thus %6 = a random number 0-5
  24. }
  25.  
  26. for(int i=0; i<6; i++){
  27. cout <<"\n\nThe number of times that "<< i+1 << " was rolled is: "<< diceOutcome[i]<<endl;
  28. cout <<"The percentage of the total that "<<i+1 << " came up was: " << (100*(diceOutcome[i] / numRolls)) << "%";
  29. }
  30.  
  31. cout <<endl;
  32.  
  33.  
  34. return 0;
  35. }
  36.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
57192
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:9: error: ‘srand’ was not declared in this scope
prog.cpp:23: error: ‘rand’ was not declared in this scope
stdout
Standard output is empty