//• Write a program that reads letters from a file called“inputLetter.txt”.
• Your program will ask the user to enter the number of games they wish to play (1 to 4)
• Your program will open the inputLetter.txt file read in one character at a time and repeat this for the number of games the user wants to play.
• For this assignment the test file will contain at least 15 letters, all lowercase
• When the number of games has been played, the program will end
• A sample of an input file that you can use to test your program is included with the assignment.
• A preprocessor directive must be used to define the maximum number of guesses as 6
• If the player has used up all of their guesses, a message that the game is over should be displayed along with the letter they were trying to guess.
• You must have at least 4 user defined functions as follows:
//this function provides instructions to the user on how to play the game
void Instructions( );
//this function runs one entire game. It for checks either 6 incorrect guesses or a correct guess.
//It returns a 0 if the game is over and the player did not guess the letter, otherwise it returns 1.
int PlayGuess(char solution);
//this function prompts the player to make a guess and returns that guess
//this function is called from inside the PlayGuess( ) function described above
char GetLetter( );
//this function takes two arguments, the guess from the player
//and the solution letter from the file.
//It lets the user know if the guess comes alphabetically before or after the answer
//The function returns 1 if the guess matches the solution and returns a 0 if they do not match
int CompareLetters(char guess, char solution);
//this is my code, i'm completely lost, i have no idea what else to do.
Code:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#define MAXGUESSES 6
//function prototypes with a comment for each one describing what the function does.
//Copy and paste from assignment
int main()
{
//variable declarations
int
i = 0;
FILE* infile;
int numberofgames;
char ans, gameFunction;
//prompt and get number of games
printf("Welcome to Letter Guess\n");
printf("You will enter the number of games you want to play (1 - 4 games)\n");
printf("You have 6 chances to guess each letter\n");
printf("Let's begin:\n\n");
printf("How many games do you want to play (1-4)");
scanf("%d",& numberofgames);
//getting the file
infile = fopen("inputLetter.txt", "r");
for(i=1;i<=numberofgames;i++)
{
fscanf(infile," %c",&ans);
printf("Let's play game %d\n", i);
PlayGuess(ans);
}
fclose(infile);
system("pause");
return 0;
}
int PlayGuess(char answer)
{
char getguess = 0;
int numGuesses = 0, numberofgames = 0;
while(numGuesses < MAXGUESSES)
{
printf("Enter a guess\n");
scanf("%c", getguess);
if(answer==getguess)
{
printf("You guessed it!!!\n");
}else{
if(answer>getguess)
{
printf("the letter you are trying to guess comes before:%d\n", getguess);
}else if(answer<getguess){
printf("the letter you are trying to guess comes after:%d\n", getguess);
}
}
numGuesses = numGuesses +1;
}
}
The out put looks like this
How many games do you want to play (1-5) 3
************************************
Let's play game 1
Enter a guess: e
the letter you are trying to guess comes before e
Enter a guess: c
the letter you are trying to guess comes before c
Enter a guess: a
You guessed it!!!
************************************
Let's play game 2
Enter a guess: t
the letter you are trying to guess comes before t
Enter a guess: a
the letter you are trying to guess comes after a
Enter a guess: p
the letter you are trying to guess comes before p
Enter a guess: n
the letter you are trying to guess comes before n
Enter a guess: g
the letter you are trying to guess comes after g
Enter a guess: k
the letter you are trying to guess comes after k
You did not guess the letter. It was m