Thread: What's wrong with this code?

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    2

    What's wrong with this code?

    so I just started out with C a couple days ago, and I was just messing around with functions and function calls and what not. And I'm getting an error when compiling this:

    Code:
    #include <stdio.h>
    
    void myFunction(void);
    
    
    
    
    int main () {
    
        int value1;
    
    printf("What is 15 multiplyed by 2?\n");
        scanf("%d", &value1);
    
        if(value1 == 30) {
    printf("That is correct");
            myFunction();
        }
        else {
    printf("That is incorrect. Try again.");
            return main();
    }
    
    
    
    
        void myFunction(void); {
        char yn;
    
    printf("Would you like another question? y/n");
        scanf("%c", &yn);
    
    }
    }
    I'm just testing it, I know the second part is completely pointless and doesn't do anything at the moment.


    NEVER MIND, realised the closing bracket for main was after myFunction.
    Last edited by andysalter; 04-03-2013 at 05:23 AM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    While not technically illegal in C, it is a really bad idea to call main() recursively.

    Try using a loop construct.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    2
    Thanks for that. Have done it with a Do..while loop instead

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is wrong with this code? please help..
    By thebridge in forum C Programming
    Replies: 2
    Last Post: 10-07-2010, 02:06 PM
  2. What is wrong with the following code?
    By steals10304 in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2009, 02:06 PM
  3. What's wrong with the code?
    By meili100 in forum C++ Programming
    Replies: 3
    Last Post: 04-09-2008, 04:11 AM
  4. What is wrong with this code?
    By ElWhapo in forum Windows Programming
    Replies: 8
    Last Post: 01-25-2005, 12:51 PM
  5. Is there anything wrong with my LCD code?
    By ooicheesan in forum C++ Programming
    Replies: 1
    Last Post: 10-18-2004, 01:13 AM