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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
//Guesses letter game
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <ctype.h>
#define MAX_GUESSES 6
//function prototypes
int main()
{
FILE* infile;
int i;
int numberofgames;
char ans;
char getguess;
int compareguess(char guess, char ans);
printf("Please enter the no of games you want to play");
scanf("%d",& numberofgames);
//variable declarations
//prompt + get numgames
//file pointer declaration
//display instructions on how to play the game
printf("Enter an letter in the range a to z\n");
printf("I will try to guess your letter with in 6 guesses\n");
printf("If you can guess my letter in 6 guesses, You Win!\n");
printf("Would you like to play?\n");
printf("Press 'Y' to play, or 'N' to quit\n");
printf("Char Playgame\n");
//connect to the file
infile = fopen("letters.txt", "r");
return 0;
}
for(i=1; i<=numberofgames; i++)
{
//print current game (value of i)
//get letter to guess from fscanf
fscanf(infile," %c",&ans);
//printf to check the letters from file
printf("%c",&ans);
//call the play function to play a game
numgames=playgame (ans);
//it will return a 1 if the user wins and a 0 if the user took more than 6 guesses
//condition here to print win or lose
numgame==0'lose';numgame==1'win';
int playgame (char ans);
{
char guess;
numberofguess=0, win or lose=0;
//call the play function to play a game
numgames=playgame (ans);
//it will return a 1 if the user wins and a 0 if the user took more than 6 guesses
//condition here to print win or lose
numgame==0'lose';
numgame==1'win';
}
return 0;
}
char GetGuess()
{
//get the users' guess
userguess = tolower(userguess);//change to lower case
//return the users' guess
return 0;
}
int compareguess(char guess, char ans)
{
//compare the guess and the answer
compare guess and ans;
//return a 1 if they are the same
return a 1 if both are the same;
//print a message based on before or after alphabetically
printf("message based on before or after alphabetically",&ans);
//return a 0 if the guess and answer are not the same
return a 0 if the guess and answer are not the same;
return 0;
}
|
Errors
(14): warning C4101: 'i' : unreferenced local variable
(17): warning C4101: 'getguess' : unreferenced local variable
(16): warning C4101: 'ans' : unreferenced local variable
(37): error C2059: syntax error : 'for'
(37): error C2143: syntax error : missing '{' before '<='
(37): error C2059: syntax error : '<='
(37): error C2143: syntax error : missing '{' before '++'
(37): error C2059: syntax error : '++'
(37): error C2059: syntax error : ')'
(67): error C2065: 'userguess' : undeclared identifier
(67): error C2065: 'userguess' : undeclared identifier
(75): error C2065: 'compare' : undeclared identifier
(75): error C2146: syntax error : missing ';' before identifier 'guess'
(75): error C2146: syntax error : missing ';' before identifier 'and'
(75): error C2065: 'and' : undeclared identifier
(75): error C2146: syntax error : missing ';' before identifier 'ans'
(77): error C2065: 'a' : undeclared identifier(77): error C2143: syntax error : missing ';' before 'constant'
(77): error C2143: syntax error : missing ';' before 'if'
(77): error C2061: syntax error : identifier 'both'(81): error C2065: 'a' : undeclared identifier
(81): error C2143: syntax error : missing ';' before 'constant'
(81): error C2143: syntax error : missing ';' before 'if'
(81): error C2061: syntax error : identifier 'the'