Thread: Hey guys. Function problem.

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    2

    Hey guys. Function problem.

    Okay, so I'm fairly decent at coding PERL, i just hate regex, and that's the only thing holding me back from mastering perl. But, this is my first post, which is why i said that, because i do have a little bit of experience programming, probably far from the average user on here lol, butw w/e... moving on.

    Okay, I'm heaving a problem moving from a function to another. I could clearly tell, that i was doing it wrong, while making this program, so i decided to stop it, and at least get it to run, without errors, which is what i did. So, please don't make fun of me because its a stupid program/coded poorly. anyways here it is:


    Code:
    #include "stdio.h"
    
    
    
    int guessednumber;
    int magicnumber = 32;
    
    int main() {
    
    printf("\nGuess your number: ");
    scanf("%d", &guessednumber);
    int numberwork;
    }
    
    
    
    
     int numberwork() {
        if (magicnumber == guessednumber) {
            printf("\n\nHoly ...., good job.");
        }
    
        else if (magicnumber > guessednumber) {
            printf("\nToo Low");
            int main();
        }
    
    else if ( magicnumber < guessednumber) {
    
        printf("\nToo high.");
        int main();
    }
    
    
    
    }
    The functions were originally "main()" and "numberwork()". but i kept getting errors. they said something like "ISO C++ forbids declaring something, blahblahblahblah..." I had the exact error, and i googled it, but only saw stuff about fixing headers, not to mention it was in C++. Oh yeah, and I'm using the MingW compiler, but im probably gonna download GCC tomorrow, cuz its what i used to use in linux. So, yeah, there it is... any help is greatly appreciated, and hopefully i can hang around here and learn a lot of stuff.

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    to call a function
    Code:
    numberwork();

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The MinGW compiler IS GCC. I have noticed that when compiling a single file, Code::Blocks will ignore the filetype and seems to always use g++, but I assume that's because I haven't figured out the right magic setting yet.

    Calling a function is just like perl -- numberwork().

    You can't call main yourself (well, you can in C, but not C++, hence the message). You shouldn't anyway. If you know perl, then you know loops, so use a loop.

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Dr.Clean View Post
    Okay, so I'm fairly decent at coding PERL, i just hate regex, and that's the only thing holding me back from mastering perl. But, this is my first post, which is why i said that, because i do have a little bit of experience programming, probably far from the average user on here lol, butw w/e... moving on.

    Okay, I'm heaving a problem moving from a function to another. I could clearly tell, that i was doing it wrong, while making this program, so i decided to stop it, and at least get it to run, without errors, which is what i did. So, please don't make fun of me because its a stupid program/coded poorly. anyways here it is:


    Code:
    #include "stdio.h"
    
    
    
    int guessednumber;
    int magicnumber = 32;
    
    int main() {
    
    printf("\nGuess your number: ");
    scanf("%d", &guessednumber);
    int numberwork;
    }
    
    
    
    
     int numberwork() {
        if (magicnumber == guessednumber) {
            printf("\n\nHoly ...., good job.");
        }
    
        else if (magicnumber > guessednumber) {
            printf("\nToo Low");
            int main();
        }
    
    else if ( magicnumber < guessednumber) {
    
        printf("\nToo high.");
        int main();
    }
    
    
    
    }
    The functions were originally "main()" and "numberwork()". but i kept getting errors. they said something like "ISO C++ forbids declaring something, blahblahblahblah..." I had the exact error, and i googled it, but only saw stuff about fixing headers, not to mention it was in C++. Oh yeah, and I'm using the MingW compiler, but im probably gonna download GCC tomorrow, cuz its what i used to use in linux. So, yeah, there it is... any help is greatly appreciated, and hopefully i can hang around here and learn a lot of stuff.
    1. Include the prototype of the function where global variables have been declared.
    2. Call the function as numberwork();
    3. Dont call main from other function, either return a value or simply dont do anything.
    By the way my question is what's the difference between "stdio.h" and <stdio.h>?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    #include "" -- searches the local directory for the header first, then include paths.
    #include <> -- the reverse of above.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    2
    Quote Originally Posted by tabstop View Post
    The MinGW compiler IS GCC. I have noticed that when compiling a single file, Code::Blocks will ignore the filetype and seems to always use g++, but I assume that's because I haven't figured out the right magic setting yet.

    Calling a function is just like perl -- numberwork().

    You can't call main yourself (well, you can in C, but not C++, hence the message). You shouldn't anyway. If you know perl, then you know loops, so use a loop.
    Alright. I just realized that I had left numberwork as "int numberwork;" while trying move to it. I had originally had it "int numberwork();", and it wasn't working so i removed the parentheses, and apparently forgot to put it back. and whoever said something about using loops... You're absolutely right lmao. Idk what i was thinking, I mean it was like midnight, and I have ADHD so my medication wasn't working anymore, but still... that was dumb of me. But, you're saying that i should probably use the project thingy, for C, cuz it will actually use the C part of it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM