Thread: Need help with code for school project!!!

  1. #1
    Registered User
    Join Date
    Aug 2015
    Posts
    1

    Need help with code for school project!!!

    I really need help with my code. I have been working on it fir an hour but just can't seem to find out what is wrong. I have posted the code below and below the code s what is wrong with it. Or you can visit the url below with a link to the code.

    Code:
    #include <stdio.h>
    
    void clean_stdin()
    {
        int c;
        do
        {
             c = getchar();
             } while (c != '\n' && c != EOF);
    }
    void endgame(void)
    {
        printf("GAME OVER");
    }
    void begingame(void)
    {
    // welcoming character
    printf("How are you today? Good or bad? \n");
    char sfeeling [5];
    scanf("%s", sfeeling);
    clean_stdin();
    printf("you are feeling %s \n", sfeeling);
    
    //Are they ready to start
    printf("Are you ready to start? y/n ");
    char ready[3]
    scanf("%s", ready);
    While ((strcmp(ready, "yes")!=0)&&(strcmp(ready,"no")!=0));
    {
        printf("invalid option, Please type "yes" or "no".);
        clean_stdin();
        scanf("%s",ready);
    }
    if (strcmp(ready,"yes")==0)
    {
        question1();
    }
    if (strcmp(ready, "no")==0) 
    {
        endgame();
    //exit(int);
    }
    
    void question1(void)
    {
        printf ("insert Question Here");
    }
    
    int main()
    {
        //main menu
        printf("game title");
        printf("By Kristian Barnes");
        printf("Type 'start' to begin game");
        printf("Type 'quit' to begine game");
        char menu[6];
        scanf("%s", menu);
        while ((strcmp(menu, "Start")!=0) && (strcmp(menu, "Quit")!=0))
        {
            printf("Invalid option. Please type 'Start' or 'Quit': ");
            clean_stdin();
            scanf("%s", menu);
        }
        if (strcmp(menu, "Start")==0)
        {
            begingame();
        }
        if (strcmp(menu, "Quit")==0)
        {
            endgame();
            return 0;
        }
    }
    Code:
    In function 'begingame':
    Line 27: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'scanf'
    Line 27: error: 'ready' undeclared (first use in this function)
    Line 27: error: (Each undeclared identifier is reported only once
    Line 27: error: for each function it appears in.)
    Line 30: error: expected ')' before 'yes'
    Line 30: error: missing terminating " character
    Line 33: error: expected ';' before '}' token
    Line 73: error: expected declaration or statement at end of input

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Welcome to the forum. In the future, be sure to paste your code "as text" so the forum syntax highlighting can do its thing.

    Let's look at the errors you posted.



    >> Line 27: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'scanf'

    This seems clear. It says you're missing something before the "scanf()" on line 27. Let's look at the previous line.

    Code:
    char ready[3]
    Do you see what is missing?

    >> Line 27: error: 'ready' undeclared (first use in this function)

    Related to the previous error - correct that one and this one will go away.

    >> Line 27: error: (Each undeclared identifier is reported only once
    >> Line 27: error: for each function it appears in.)


    Related to the previous error - correct that one and this one will go away.

    >> Line 30: error: expected ')' before 'yes'

    Let's look at this line of code.

    Code:
    printf("invalid option, Please type "yes" or "no".);
    If you want to print quotes, you need to escape them (\"). The way it is now, you're ending your formatting string prematurely.

    >> Line 30: error: missing terminating " character

    Related to the previous error - correct that one and this one will go away.

    >> Line 33: error: expected ';' before '}' token
    >> Line 73: error: expected declaration or statement at end of input


    Things start getting wonky because your opening braces do not appear to match your closing braces. More consistent indentation will help you see mistakes like this much easier.

    This is also concerning:

    Code:
    While ((strcmp(ready, "yes")!=0)&&(strcmp(ready,"no")!=0));
    C is case sensitive, and it is "while", not "While". Also, you do not want that semi-colon at the end.



    I'll let you in on a little secret to writing good programs. Start small - just a few lines of code that does only one thing. Compile, fix all your errors and warnings, test, and fix. Once that is working, add just a little bit more code - compile, fix, test. Repeat this process, gradually building your program and testing as you go.

    See here for a detailed example: A development process

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my school project!!!
    By Maciek Grodzki in forum C Programming
    Replies: 5
    Last Post: 01-07-2014, 07:53 AM
  2. School Project Help
    By Joshua Hess in forum C++ Programming
    Replies: 9
    Last Post: 02-19-2013, 07:27 PM
  3. Pseudo-code for a school project
    By Yashabee in forum C Programming
    Replies: 2
    Last Post: 01-16-2013, 10:28 PM
  4. school project help
    By yogai in forum C Programming
    Replies: 8
    Last Post: 09-09-2004, 06:03 PM
  5. Help with School Project
    By jtouron in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2003, 12:27 AM

Tags for this Thread