fork(3) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <ctype.h>
  6.  
  7. int main (){
  8.  
  9. int die1, die2;
  10. int dicesum;
  11.  
  12. //ints for rolling a 7, 11, 2, 3, or 12
  13. int instantwin;
  14. int instantlose;
  15.  
  16.  
  17. int sumpoints;
  18.  
  19. //int points for rolling anything other than the above on the first go, and
  20. int losepoints;
  21. int pointstotal;
  22.  
  23.  
  24. int i;
  25.  
  26.  
  27. instantwin = 0; instantlose = 0; pointstotal = 0; losepoints = 0;
  28.  
  29. for (i=0;i<100;i++){
  30.  
  31. srand(time(NULL));
  32.  
  33. die1 = rand () % (6-1)+1;
  34. die2 = rand () % (6-1)+1;
  35.  
  36. dicesum = die1+die2;
  37.  
  38. switch (dicesum){
  39. case 7: case 11:
  40. printf ("\nYou won with a roll of %d\n", dicesum);
  41. instantwin++; break;
  42.  
  43. case 2: case 3: case 12:
  44. printf ("\nYour roll of %d is craps. You lost!\n", dicesum);
  45. instantlose++; break;
  46.  
  47. default:
  48. die1 = rand () % (6-1)+1;
  49. die2 = rand () % (6-1)+1;
  50. sumpoints = die1+die2;
  51.  
  52. if (dicesum==4 || dicesum==5 || dicesum==6 || dicesum==8 || dicesum==9 || dicesum==10){
  53. sumpoints=pointstotal;
  54. }
  55.  
  56. else if (dicesum==7){
  57. losepoints++;
  58. pointstotal=0;
  59. }
  60.  
  61. }
  62.  
  63. }
  64.  
  65. printf ("\nResults");
  66. printf ("\n%d Instant wins", instantwin);
  67. printf ("\n%d Instant losses", instantlose);
  68. printf ("\n%d Total points earned", pointstotal);
  69. printf ("\n%d Points lost", losepoints);
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0.02s 1676KB
stdin
Standard input is empty
stdout
Results
0 Instant wins
0 Instant losses
0 Total points earned
0 Points lost