Helpful Information
 
 
Category: Dev Shed Gaming Center
Help with hangman

Can someone please help me. My code wont compile because it says 'letternum' is and undefined symbol and 'list' is as well even though I have them defined in a constant expression. This only started happening when I put in the switch statement. I'm very new to programming and any help would be greatly appreciated :D

here is my code:
//Hangman Assignment
// 19/11/12
#include<stdio.h>
#define letters 5

main()
{
char word[letters] = {'t','r', 'i', 'c', 'k'};
char guess_word[letters];
char letter;
int location;
int tries = 0;
int i = 0;
int search(const char list[], int letternum, char letter);
int startmenu, PlayGame, ExitGame;

printf("Lets PLay Hangman!");
printf("\n1. Play game\n0. Exit");
scanf("%d",&startmenu);

switch ( startmenu )// The user interface menu
{
case 1:
{
for( i = 0; i < letters; i++ )
guess_word[i] = '_';

do
{
printf("choose a letter: ");
scanf("%1s", &letter);

location = search(word, letters, letter);

if ( location != -1 )
{
printf("%c was found\n", letter);
guess_word[location] = letter;
for( i = 0; i < letters; i++ )
printf(" %c",guess_word[i]);
printf("\n");
}

else printf("%c was not found\n", letter);

++tries;
}

while(tries < 6);

return 0;
}

int search(const char list[], int letternum, char letter);
{
int i = 0, found = 0;


while (i < letternum && !found)
{
if (list[i] == letter) found = 1;

else i++;
}

if( found == 1 )
return i;
else
return -1;
}

case 0:
{
return 0;
} // End case 0



} // End switch

getchar();
}










privacy (GDPR)