-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrandom.c
executable file
·57 lines (45 loc) · 1.57 KB
/
random.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* Definindo o número limite para a pessoa tentar descobrir */
#define LIMITE 10
#define ENCERRA printf("Pressione ENTER para continuar!\n"); while(!getchar());
int main (int argc, char** argv)
{
int numeroPensado=0, numeroDoUsuario=0, limiteTentativas=(LIMITE/2)-1, maximoTentativas=0,i;
srand(time(NULL)); // Serve para modificar a tabela de números pseudo-aleatórios
numeroPensado=rand()%LIMITE+1;
printf("OK! Pensei em um número entre 1 e %d e te desafio a achar ele!\n", LIMITE);
do
{
printf("Quantas tentativas você acha que precisa para descobrir ele? ");
scanf("%d",&maximoTentativas);
if (maximoTentativas<1)
printf("Você precisa tentar ao menos uma vez! :P\n");
if (maximoTentativas>limiteTentativas)
printf("%d tentativas? Tá querendo demais também! :P\n",maximoTentativas);
} while (maximoTentativas<1 || maximoTentativas>limiteTentativas);
// for (i=1; i<=maximoTentativas;i++)
for (i=1; --maximoTentativas; i++)
{
printf("Vamos lá! %da. tentativa! ",i);
scanf("%d",&numeroDoUsuario);
if (numeroDoUsuario==numeroPensado)
{
printf("Parabéns! Você acertou!\n");
ENCERRA
return(0);
}
else
{
printf("Não pensei em %d. ", numeroDoUsuario);
if (numeroDoUsuario<numeroPensado)
printf("Pensei em um número maior.\n");
if (numeroDoUsuario>numeroPensado)
printf("Pensei em um número menor.\n");
}
}
printf("Que pena! Eu pensei em %d! Melhor sorte da próxima vez! \n",numeroPensado);
ENCERRA
return(0);
}