Thread: First post !

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

    First post !

    Hey ! i dont want to be a jerk by making my first post a question and not a reply buuut...

    So i am trying to get back into programming as a hobby i havent done it since highschool ! i used a little c# in grade 12 but dont remember much. Anyway im trying to learn c++ now and am a little stuck, probly a simple fix but here it is.

    i am just mucking around and trying to make a simple program to just ask if you want to use my simple calculator "calc extreme" or if you want to retrun to the start of the program etc.. anyway when i compile it i get a error in this part of the code..it says main is not declaired in this scope, whgat i dont get is that i call the old member and membername and dotn get that error but when i want the program to return to the main func it gives a error ? i tried to move the main funct around and it didnt seem to help. any one who can shine some light on a newbie i would be so grateful!

    Code:
    string oldmember()
    {
    
    
        int selection;
    
    cout<<"Welcome back to the club!\n";
    cout<<"What can we do for you today?\n";
    cout<<"1-Calculator extreme\n 2-main menu: ";
    cin>>selection;
    
    if (selection==1)
    calculator();
    else if(selection==2)
    main();
    //else
    //cout<<"please try again";
    //goto c;
    }
    
    int main()
    {
        char member;
    
        c:
        cout<<"Welcome to the club\n";
        cout<<"Are you a new member? (Y/N)";
        cin>>member;
    
        if ((member=='Y') || (member=='y'))
           membername();
        else if ((member=='N') || (member=='n'))
           oldmember();
        else
        cout<<"Please try again\n";
        goto c;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Err... before you proceed:
    • Indent your code properly.
    • Use a loop instead of calling the global main function recursively.
    • Do not use goto. In this case, a loop will suffice.
    • Post the smallest and simplest compilable program that demonstrates the problem. If the problem is a compile error, then post the smallest and simplest program that you expect to compile but which does not, and then also post the error message.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You should address what laserlight said. But I can give you insight on why it fails.
    The compiler parses the source file top to bottom. So when it encounters main inside oldmember, it hasn't been defined yet. So the compiler barks.
    To fix it, one would usually put prototypes of each function at the top of the source file. However, main is special, so you shouldn't call it recursively.

    Also, there is no shame in making a first post with a question. That is what people usually do. Come for help. So they register and they post a question. Perfectly normal.
    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.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Posts
    2
    sweet, thanks for the help!

    So indenting just makes it look clean correct ?

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Indenting makes the code readable, pretty and helps find bugs, such as misplaced braces.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help (Trying to post message)
    By mrkm in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-06-2003, 04:05 PM
  2. Post your Best Text Adventure
    By Joe100 in forum Game Programming
    Replies: 3
    Last Post: 08-15-2003, 05:47 PM
  3. Auto POST
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-07-2003, 10:42 AM
  4. post update
    By iain in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-12-2001, 10:47 AM