I want my my program to look just like the one below (as in showing what guess # they are on ):I've been working on this for the past hour or so but I just can't seem, to get it right . Can someone help me?
For example i keep getting(after debugging):
Enter your choice of letter: A
I am sorry but your guess is too LOW
but I want it to look like the one below(as in 1:,2:ect). can anybody help me please?:
Enter your choice of letter 1: A
I am sorry but your guess is too LOW.
Enter your choice of letter 2: Z
I am sorry but your guess is too HIGH.
Enter your choice of letter 3: B
I am sorry but your guess is too LOW.
...ect.
My code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define WIN 'W'
#define LOSE 'L'
#define _CRT_SECURE_NO_WARNINGS
#define MAX_GUESSES 6
// This function displays game instructions, and returns nothing.
void Instructions();
// This function plays one game, and returns "W" if the player wins
// or "L" if the player runs out of guesses.
char Play();
//this function prompts the player to make a guess and returns that guess
char guess();
// This function returns a random letter between "A" and "Z
char GetAnswer();
int main()
{
char answer;
//1. Greet the user and ask if they would like to play a guessing game.
//2. As long as the answer is "Y" or "y", display instructions for playing the game. Otherwise, let the program end with a return codeof -1.
printf("Hello there!\n\nWould like to play a guessing game?Enter Y or N: \n");
scanf(" %c", &answer);
if(answer == 'Y' || answer == 'y')
{
printf("\nYou entered Y. Let's play!\n");
Instructions();
Play();
}
else
{
printf("\nMaybe next time.\n");
printf("\nGoodBye for now.\n");
return -1;
//if else to return W or return L for 0 and -1
answer=Play();
if (answer == 'W' )
{
return 0;
}
else if (answer == 'L')
{
return -1;
}
}
}
//this function provides instructions to the user on how to play the game
void Instructions()
{
printf("\nI have a capital letter in mind. You have 6 chances to guess which letter I am \nthinking. I will let you know if you are too high or too low.\n");
printf("After each guess, you will be informed if your guess is too high or too low.\nGood luck!\n");
}
char Play()
{
// set guesses so far to zero
int guess = 0;
// user entered letter guess
char entered_guess;
// the correct "Random" letter
char correct_Letter;
correct_Letter = GetAnswer();
printf("\nHow many times would you like to play:\n ");
scanf("%d", &guess);
if(guess < 0)
{
printf("Sorry, you can't enter anything lower than 0.\n");
Play();
return -1;
}
if (guess > 6)
{
//
printf("Sorry, you are only allowed 6 guesses.\n");
printf("\nTry again\n");
Play();
return -1;
}
while (guess )
{
//Start of the game
printf("\n\nEnter your choice of letter: ");
scanf(" %c", &entered_guess);
//The player gets up to 6 guesses. If they guess correctly, congratulate them and let the program end with a return code of 0.
if (entered_guess == correct_Letter)
{
printf("Wow! You guessed it!");
printf("\nCongratulations! You win!\n");
printf("\nGoodbye for now!\n");
return 0;
}
//If the player does not guess the right answer, display whether the guess is "too high" or "too low".
else if(entered_guess < correct_Letter)
{
printf("I am sorry but your guess is too LOW.");
}
else
{
printf("I am sorry but your guess is too HIGH.");
}
guess= guess-1;
if(guess==0)
// If the player guesses wrong for a 6th time, console them and let the program end with a return code of 1.
{
printf("\n\nIt looks like you have run out of guesses. I am sorry, but you lose!");
printf("\n\nThe letter I had in mind was %c ",correct_Letter);
printf("\nGoodbye for now!\n");
}
}
return 1;
}
///player defined guesses.
//Generate a "random" character between 'A' and 'Z'. This will be the value the player will try to guess.
char GetAnswer()
{
srand((unsigned int) time(NULL));
return ((rand() % 26) + 'A');
}