int main()

This is a discussion on int main() within the C++ Programming forums, part of the General Programming Boards category; ok, when you get an "if" to loopback to the main by putting in main(); , how can I get ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    9

    int main()

    ok, when you get an "if" to loopback to the main by putting in main(); , how can I get it to loopback to a different "if" instead of the original main() at the top?

  2. #2
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    Posts
    125
    Can you be more specific and may be even post the source code you are having problems with?
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    49

    Umm..

    Use the goto(); command?
    i'm not stupid, just a little short on brains.
    Kav's game!
    Featuring:
    # - Goodguy mc goodguy
    * - Bad guy mc badguy
    $ - Princess Mc Cess
    @ - Mcdonalds Mc chicken! mmmmmm

  4. #4
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    You shouldn't make explicit calls to main(). You can use exception handling for breaking code blocks, however it really depends on the actual problem.

  5. #5
    Unregistered
    Guest
    Dunno if this is acceptable programming style, but it works for me. Why not use function calls as part of your ifs?

    #include <iostream.h>

    int someFunction1(int &);
    void someFunction2(int &);

    int main()
    {
    int signal = -1;
    int whatDrive;

    cout << "Starting execution." << endl;

    for(;
    {
    whatDrive = someFunction1(signal);

    if(whatDrive == 0)
    someFunction2(whatDrive);
    else if(whatDrive == 1)
    cout << "do this" << endl;
    else
    {
    cout << "do nothing" << endl;
    break;
    }

    signal ++;
    }

    cout << endl << "Returned from two function calls ok.";

    return 0;
    }

    int someFunction1(int &counter)
    {
    int tryMe;

    tryMe = counter + 1;

    return tryMe;
    }

    void someFunction2(int &stuff)
    {
    cout << "the drive is: " << stuff << endl;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 04:34 PM
  2. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  3. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 05:40 PM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-01-2003, 11:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21