Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

instructions outline for program. 1-gues: ) Large Program I guess guess game STE

ID: 3757491 • Letter: I

Question

instructions

outline for program.

1-gues: ) Large Program I guess guess game STEPS (1)-F Large Program I guess t guessgameSTEPSj/X + ****Please do only one step at a time and do not move onto the next step until you have compiled and tested the current step Download the guessGame exe file and letters.txt file to play a few rounds of the game (YOU MAY NEED TO CONNECT TO THE ENGINEERING STUDENT DESKTOPS TO TRY IT) Write and submit the algorithm Create a project and name the source code guessGame.c Use the sample guessGameOutline as a guide, copy/ paste into your project source code 1. 2. 3. ** build run and test, the outline code should compile and execute 4. 5. Add the function prototype and implement the function definition for the GameRules function Add the function call to GameRules in the main function ***build run and test 6. Go to the assignment and save letters.txt into the same directory as guessGame.c (remember to use your Z drive on portal eng. fau.edu) 7. Declare a file pointer variable, connect to the input file before the do/ while loop begins, use fopen 8. Use fscanf INSIDE the do/while loop body to read the letters one by one from the file 9. Remember to add the space in fscanf for %c 10. Use printf statements to see the letters from the file print onto the screen (inside the loop) Yes, these are the solution letters, if you want to play the game later you can have a friend put different letters in the letters.txt file ***build run and test GET HELP HERE IF YOU CANNOT CONNECT, READ AND PRINT THE LETTERS FROM THE FILE) 11. Use the toupper function (from ctype.h) to change each letter from the file to upper case a. solution toupper (solution); 12. use printf statements to see the letters from the file print onto the screen, after you are sure this is working, you ch

Explanation / Answer

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <ctype.h>
#define MAXGUESSES 5


//paste all the function prototypes here
//with the comments

//this function provides instructions to the user on how to play the game
void LetterGuessRules();

//this function asks, gets, and //returns the number of games the user wants to play
int GameCount();

//this function runs one game.
//input: character from the file, void return type
void PlayOneGame(char solution);

//this function prompts the player to make a guess and returns that guess
//this function is called from inside the PlayOneGame( ) function described above
char GetGuess();

//this function takes two arguments, the guess from the player
//and the solution letter from the file.
//The function returns 1 if the guess matches the solution and returns a 0 if they do not match
//This function also lets the user know if the guess comes alphabetically before or after the answer
int CompareGuessAndSolution(char guess, char solution);


int main()
{
   //declare additional variables
   //declare FILE pointer
   FILE *inPtr;
   int numGames, i = 0;

   char solution; //letter from file

   LetterGuessRules(); //display game rules

   numGames=GameCount(); //Ask and get number of games to play (GameCount function)

   inPtr = fopen("letters.txt", "r"); //connect to the file HINT: use fopen

   //this for loop will allow the player to play more than one game
   //without recompiling
   for (i = 0; i < numGames; i++)
   {
       fscanf(inPtr, " %c", &solution); //get a solution letter from file - use fscanf

       solution = toupper(solution); //change the solution to uppercase

       //printf(" The letter is %c", solution); //print the solution back onto the screen to test<-Step 14. THIS WORKS!

       printf(" ****************** ");
       printf(" Let's play game %d. ", i+1); //shows user what round they are on.

       //call the PlayOneGame function and pass it the solution
       PlayOneGame(solution);

   }

   //close file pointer
   fclose(inPtr);
   return 0;
}

//this function provides instructions to the user on how to play the game
void LetterGuessRules()
{
   printf("Welcome to the Letter Guessing Game! ");
   printf("First, you will enter the number of games you want to play (1-8 games). ");
   printf("For each game you will have 5 chances to guess each letter. ");
   printf("Let's begin. ");
}

//this function asks, gets, and //returns the number of games the user wants to play
int GameCount()
{
   int numGames; //input from user amount of games to play
   printf(" How many games do you want to play? (1-8) ");
   scanf("%d", &numGames);
   printf(" You want to play %d games. ", numGames); //repeats back to user how many games they want to play.
   return numGames;
}

//this function runs one game.
//input: character from the file, void return type
void PlayOneGame(char solution)
{

   int win = 0;
   int numGuesses = 0;
   //declare additional variables
   char guess; //user's letter guess

   //printf(" The letter is %c", solution);<-Step 16 works and letters are uppercase.

   while (numGuesses < MAXGUESSES && win == 0)
   {
       //get a guess from the user by calling the GetGuess function
       guess = GetGuess();

       //change the guess to uppercase.
       guess = toupper(guess);
      
       //printf("Your guess is %c.", guess);<-STEP 21. This works and letter is uppercase.
      
       //win = call the function to compare the guess with the solution
       win = CompareGuessAndSolution(guess, solution);

       numGuesses++;//count the number of guesses so far
   }
   //use conditions to let the user know if they won or lost the round of the game
   if (numGuesses < MAXGUESSES && solution == guess) //If they guess correctly and win the round.
   {
       printf(" You've won this round! ");
   }
   else if (numGuesses == MAXGUESSES && solution != guess) //If they run out of guesses for the round.
   {
       printf("You've run out of guesses for this round. ");
   }
   else if (numGuesses == MAXGUESSES && solution == guess) //If they guess correctly on the last available guess and win.
   {
       printf(" You won that round on your last guess! ");
   }

}

//this function prompts the player to make a guess and returns that guess
//this function is called from inside the PlayOneGame( ) function described above
char GetGuess()
{
   char guess; //user's letter guess

   printf(" Please make a guess: ");
   scanf(" %c", &guess);

   return guess;
}

//this function takes two arguments, the guess from the player
//and the solution letter from the file.
//The function returns 1 if the guess matches the solution and returns a 0 if they do not match
//This function also lets the user know if the guess comes alphabetically before or after the answer
int CompareGuessAndSolution(char guess, char solution)
{
   //correct guess
   if (guess == solution)
   {
       printf(" That is correct!");
       return 1;
   }
   //incorrect guess: pick letter before user guess
   else
       if (guess > solution)
       {
           printf(" The solution comes alphabetically before your guess (%c). ", guess);
           return 0;
       }
   //incorrect guess: pick letter after user guess
   else
       if (guess < solution)
       {
           printf(" The solutions comes alphabetically after your guess (%c). ", guess);
           return 0;
       }
       else return 0;
}