-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjogo_adivinhacao.c
59 lines (49 loc) · 1.77 KB
/
jogo_adivinhacao.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
58
59
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void jogo() {
// Gera o número aleatório
srand(time(NULL));
int numeroAleatorio = rand() % 101;
int numero;
int tentativas = 0;
// Loop que verifica se o número aleatório é igual ao inserido
while (numero != numeroAleatorio) {
printf("\nDigite um valor: ");
scanf("%d", &numero);
if (numero == numeroAleatorio) {
printf("------------------------------\n");
if (tentativas <= 3) {
printf("VOCE ACERTOU EM MENOS DE 4 TENTATIVAS! IMPRESSIONANTE!");
printf("\nNumero de tentativas: %d", tentativas);
} else if (tentativas <= 5) {
printf("Voce acertou em menos de 6 tentativas! Legal!");
printf("\nNumero de tentativas: %d", tentativas);
} else {
printf("Parabens, voce acertou!");
printf("\nNumero de tentativas: %d", tentativas);
}
} else if (numero < numeroAleatorio) {
printf("O numero inserido e menor que o numero secreto!");
tentativas++;
} else if (numero > numeroAleatorio) {
printf("O numero inserido e maior que o numero secreto!");
tentativas++;
}
}
char replay;
printf("\n------------------------------");
printf("\nGOSTARIA DE TENTAR NOVAMENTE?\n[s/n] ");
scanf(" %c", &replay);
if (replay=='s') {
jogo();
}
}
int main() {
// Interface do programa
printf("------------------------------\n");
printf("TENTE ADIVINHAR O NUMERO!\nDica: Ele esta entre 0 e 100\n");
printf("------------------------------");
jogo();
return 0;
}