Here is the code if you don't feel like downloading the c file
insert
Code:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#define MAXGUESSES 5
//function prototypes with a comment for each one describing what the function does.
//Provides user with the instructions on how to play the game
void GameRules(void);
//It runs one entire game. It checks either five incorrect guesses or one correct guess.
//This also returns a 0 if the game ended with the player not guessing the correct letter, if not it returns a 1.
int SingleGame(char file_letter);
//Prompts a player to make a guess and returns said guess
//It is located inside the single game function from above
char RetrieveGuess();
//Takes two arguments, both the guess from the player and the solution from the file
//Lets the player know if the guess comes alphabetically before or after the answer
//It returns a 1 if the guess matches, and returns a 0 if it does not match
//This is located inside the OneGame() funciton from above
int GuessedIt(char answer, char input_letter);
//Copy and paste from assignment
int main()
{
//declare additional variables
int PlayGames = 4,
i = 0;
char file_letter,
answer,
input_letter;
int GuessedIt(char answer, char input_letter);
//display instructions
GameRules();
//open file
FILE * inPtr;
inPtr = fopen("lettersin.txt", "r");
//get number of games to play
printf("How many games do you wish to play?\n");
scanf(" %d", &PlayGames);
for (i = 0; i<PlayGames; i++)
{
//get a letter from file
fscanf(inPtr, " %c", &file_letter);
//Play one game
SingleGame(file_letter);
printf("The letter is %c\n", file_letter);
//check for win or lose
GuessedIt(answer, input_letter);
}
//close file
fclose(inPtr);
return 0;
}
//Function definitions
//copy and paste prototypes and comments from assignment. Then remove the ; from each
//Provides user with the instructions on how to play the game
void GameRules(void)
{
printf("Letter Guessing Game\n");
printf("Input how many times you want to play the game\n");
printf("You have 5 chances to guess each of the letters\n");
printf("Start\n");
}
int SingleGame(char file_letter)
{
int numGuesses = 0;
while (numGuesses < MAXGUESSES)
{
//RetrieveGuess function call
RetrieveGuess();
//GuessedIt function call
GuessedIt(answer, input_letter);
//update counter for number of guesses used
printf("number of guesses is %d\n", numGuesses);
numGuesses = numGuesses + 1;
}
//Prompts a player to make a guess and returns said guess
//It is located inside the single game function from above
char RetrieveGuess()
{
char input_letter;
printf("Enter a letter: ");
scanf(" %c", &input_letter);
return input_letter;
}
//Takes two arguments, both the guess from the player and the solution from the file
//Lets the player know if the guess comes alphabetically before or after the answer
//It returns a 1 if the guess matches, and returns a 0 if it does not match
//This is located inside the OneGame() funciton from above
int GuessedIt(char answer, char input_letter)
{
char value;
if (answer < input_letter)value = 0;
else value = 1;
printf("letter comes before");
return 0;
}
}