Syntax Issue with If Condition

Hello again,

I was just wondering if anyone would be able to clarify a syntax issue I am having. It is towards the bottom of my code in the CompareLetters function and is dealing with the first if statement. Why am I getting an expected '=' message on the == and an expected expression message after the closing parenthesis. I have absolutely no idea why it is doing that and every reference I go to has their if statements just like mine. If someone could help me out, I would really appreciate it. Thanks.

P.S. I know a whole lot of the rest of the code is badly messed up. I am in the middle of a project. I would be more than open to any addition help though :)

EDIT: Also, in the PlayGuess function, when I try to call on the CompareLetters function, it will not allow me to enter ANYTHING in the parameters. If anyone is willing to take a loot at that for me, I will be forever in your debt!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <ctype.h>

#define MAX_GUESSES 5

void Instructions();
int PlayGuess(char solution);
char GetLetter();
int CompareLetters(char guess, char solution);


int main ()
{
	Instructions();
	
	return 0;
}

void Instructions ()
{
	printf("Hello, and welcome to the letter guessing game.\n");
	printf("You will be allowed five guesses for up to four games, depending on how many you wish to play.\n");
	printf("The goal is simple; just keep guessing different letters until \nyou choose the correct one.\n");
	printf("After each guess, you will be informed if the solution is alphabetically behind or ahead of your guess.");
	printf("If the correct letter is chosen, the game is over and you have won!\n");
	printf("If you fail to choose the correct letter after your fifth try, you lose.\n");
	printf("Okay, now lets begin.\n");
}

int PlayGuess(char solution)
{
	int NumGuesses=0; int WinOrLose=0;

	while (NumGuesses < MAX_GUESSES && WinOrLose==0);
	{
		GetLetter();
		CompareLetters();
		NumGuesses++;
	}


}

char GetLetter()
{
	printf("Please enter your letter guess: ");
	char UserGuess;
	scanf("%c", &UserGuess);
	UserGuess = tolower(UserGuess);
	return UserGuess;
}

int CompareLetters(char guess, char solution)
{
	if(char guess == char solution)
	{
		return 1;
	}
	else
	{
		return 0;
	}

}

Last edited on
Line 55: Remove the char from the statement.
 
	if(guess == solution)


I just did that but still no luck :/
Line 37: You're trying to call CompareLetters without specifying any arguments.

What are the exact errors are you're getting?

Edit: In PlayGuess, you need both solution and guess so you can pass them to Compare letters. Then you need to do something with the result returned by CompareLetters.

Last edited on
Topic archived. No new replies allowed.