Created
January 12, 2015 14:21
-
-
Save mauricioaniche/d859d17fd635b52bf8e1 to your computer and use it in GitHub Desktop.
Forca - Funções - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void abertura() { | |
printf("/****************/\n"); | |
printf("/ Jogo de Forca */\n"); | |
printf("/****************/\n\n"); | |
} | |
int main() { | |
char palavrasecreta[20]; | |
sprintf(palavrasecreta, "MELANCIA"); | |
int acertou = 0; | |
int enforcou = 0; | |
char chutes[26]; | |
int tentativas = 0; | |
abertura(); | |
do { | |
for(int i = 0; i < strlen(palavrasecreta); i++) { | |
int achou = 0; | |
for(int j = 0; j < tentativas; j++) { | |
if(chutes[j] == palavrasecreta[i]) { | |
achou = 1; | |
break; | |
} | |
} | |
if(achou) { | |
printf("%c ", palavrasecreta[i]); | |
} else { | |
printf("_ "); | |
} | |
} | |
printf("\n"); | |
char chute; | |
printf("Qual letra? "); | |
scanf(" %c", &chute); | |
chutes[tentativas] = chute; | |
tentativas++; | |
} while (!acertou && !enforcou); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment