I built a letter guessing game and basically the user enters the number of games they want to play, I get a letter from the file, user enters a guess, and i tell them if they are right or not. What i want to do is print "Ready for game #1" after they enter the number of games and also "Getting guess #1" before getting the guess letter. I know its from the loop "i" but i can't seem to figure it out. Here is my code
C
#define _CRT_SECURE_NO_WARNGINGS
#include<stdio.h>
#include<ctype.h>
#define MAXGUESSES 5
//this function provides instructions to the user on how to play the game
void GameRules();
//this function runs one game.
//input: character from the file, void return type
//all other functions to Play one round of a game
//are called from within the GuessTheLetter function
void GuessTheLetter(char);
//this function prompts the player to make a guess and returns that guess
//this function is called from inside the GuessTheLetter( ) function described above
char GetTheGuess();
//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 CompareLetters(char, char);
int main() {
FILE *inPtr;
int numGames, i = 0;
char letter;//letter from file
printf("Welcome to the Letter Guessing Game\n");
GameRules();
printf("How many games? (1 to 8)\n");
scanf("%d", &numGames);
inPtr = fopen("letterList.txt", "r");
for (i = 0; i < numGames; i++) {
fscanf(inPtr, " %c", &letter);
letter = tolower(letter);
GuessTheLetter(letter);
}
return 0;
}
void GuessTheLetter(letter) {
int win = 0;
int numGuesses = 0;
char guess;
while (numGuesses < MAXGUESSES && win == 0) {
guess = GetTheGuess();
guess = tolower(guess);
win = CompareLetters(letter, guess);
numGuesses++;
}
if (win == 1) {
printf("And you Won !!!\n");
}
else {
printf("SORRY, you did not win this round\n");
}
}
char GetTheGuess() {
char guessEntered;
printf("Enter a guess\n");
scanf(" %c", &guessEntered);
return guessEntered;
}
int CompareLetters(letter, guess) {
int winGet;
if (letter == guess) {
printf("The solution and the guess are the same ( %c )", letter);
winGet = 1;
}
else if (letter != guess) {
printf("The solution comes before your guess ( %c )", letter);
winGet = 0;
}
else {
printf("Error!");
}
return winGet;
}
void GameRules() {
printf("First, you will enter the number of games you want to play(1 - 8 games)\n");
printf("For each game you will have 5 chances to guess each letter\n");
printf("Let's begin:\n\n");
}