Jvsierra

Craps

Jun 21st, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5.  
  6. #define MAX 6
  7.  
  8. int rodaDados(int * d1, int * d2);
  9. void mostraValores(int d1, int d2);
  10.  
  11. int main()
  12. {
  13.     int d1, d2, ponto, soma;
  14.     srand(time(NULL));
  15.    
  16.     rodaDados(&d1, &d2);
  17.    
  18.     mostraValores(d1, d2);
  19.    
  20.     soma = d1 + d2;
  21.    
  22.     if(soma == 7 || soma == 11)
  23.         printf("O jogador venceu\n");
  24.     else if(soma == 2 || soma == 3 || soma == 12)
  25.         printf("A casa vence\n");
  26.     else
  27.     {
  28.         ponto = soma;
  29.        
  30.         rodaDados(&d1, &d2);
  31.        
  32.         soma = d1 + d2;
  33.        
  34.         mostraValores(d1, d2);
  35.        
  36.         while(soma != ponto && soma != 7)
  37.         {
  38.             rodaDados(&d1, &d2);
  39.             soma = d1 + d2;
  40.            
  41.             mostraValores(d1, d2);
  42.         }
  43.            
  44.         if(soma == 7)
  45.             printf("O jogador perdeu\n");
  46.         else
  47.             printf("O jogador ganhou\n");
  48.     }
  49.    
  50.     getch();
  51. }
  52.  
  53. int rodaDados(int * d1, int * d2)
  54. {
  55.     *d1 = rand() % MAX + 1;
  56.     *d2 = rand() % MAX + 1;
  57. }
  58.  
  59. void mostraValores(int d1, int d2)
  60. {
  61.     printf("Dado 1 = %d\n", d1);
  62.     printf("Dado 2 = %d\n", d2);
  63.     printf("Soma = %d\n", d1 + d2);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment