victorialais

Questão 6. Adivinhar o número de 0 a 100

Aug 19th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. int main() {
  6.   int numero, x;
  7.   int tentativas = 1;
  8.   char s = 't';
  9.  
  10.   srand(time(NULL));
  11.   x = rand() % 100 + 1;
  12.  
  13.   printf("Advinhe o número de 0 a 100\n\n");
  14.  
  15.  
  16.   do {
  17.   printf("\nDigite um número: ");
  18.   scanf("%d", &numero);
  19.  
  20.     if (numero > x) {
  21.       printf("O número certo é menor do que a tentativa feita");
  22.     }
  23.     else {
  24.       if (numero < x)
  25.         printf("O número certo é maior do que a tentativa feita");  
  26.       else {
  27.         printf("\nVocê acertou o número");
  28.         printf("\nNúmero de tentativas: %d", &tentativas);
  29.         printf("\n %d é o número certo", x);
  30.       }
  31.     }
  32.  
  33.  /* tentativas++;
  34.   } while (num != x && tentativas <= 20);
  35.  
  36.   if (tentativas > 20) {
  37.     printf("\n\nVOCÊ ULTRAPASSOU O LIMITE DE TENTATIVAS! TENTE OUTRA VEZ!");
  38.     printf("\nO número era: %d", x);
  39.   }
  40. */
  41.   while (s != 's' && s != 'n') {
  42.     printf("\n\nDeseja tentar novamente? [s/n]: ");
  43.     scanf("%c", &s);
  44.  
  45.     if (s == 's')
  46.       main();
  47.   }
  48.  
  49.   return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment