Buscar

genius

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

#include <stdio.h>
#include <time.h>
void genius(int max);
void voceErrou(int max);
void main(){
 int nivel, max;
 printf("1 - Facil (0 a 4)\n");
 printf("2 - Medio (0 a 8)\n");
 printf("3 - Dificil (0 a 12)\n\n");
 printf("Digite o nivel: ");
 scanf("%d", &nivel);
 if (nivel == 1){
 max = 4;
 } else if (nivel == 2){
 max = 8;
 } else {
 max = 12;
 }
 genius(max);
}
void genius(int max)
{
 int numAleatorio;
 char c;
 srand(time(NULL));
 numAleatorio = rand() % max;
 int numero, jogadas = 0;
 do {
 printf("%i", numAleatorio);
 printf("\nDigite o número: ");
 scanf("%i", &numero);
 if (numero != numAleatorio)
 {
 break;
 }
 else
 {
 numAleatorio = rand() % max;
 jogadas++;
 }
 
 
 } while (jogadas < max);
 
 if (jogadas == max)
 {
 printf("\nParabéns, você venceu!\n");
 }
 else if (jogadas < max)
 {
 voceErrou(max);
 }
}
void voceErrou(max)
{
 int c;
 fflush(stdout);
 printf("\nVocê errou! Jogar novamente? (1 - Sim/ 2 - Não) > ");
 fflush(stdin);
 scanf("%i", &c);
 
 if (c == 1)
 {
 genius(max);
 }
}

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Continue navegando