Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Hangman assignment help in C

Options
  • 19-11-2012 5:29pm
    #1
    Registered Users Posts: 2


    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:)

    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 = '_';

    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);
    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 == letter) found = 1;

    else i++;
    }

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

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



    } // End switch

    getchar();
    }


Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.

Advertisement