Thread: stupid question need quick answer

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    2

    Arrow stupid question need quick answer

    how do I make the file just stop

    for example I'm writing tic tac toe and after every move I want the program to check to see if either side has won

    if it checks and sees that a side has won it sets a variable 'win = 1'

    so now I want to do

    If (win==1)
    End program

    but I don't know how to end the program

    maybe I should use a goto statement, but I don't know how those work either

    anyone?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    How does your main loop look like?
    It should look something like this:
    Code:
    int main()
    {
       while(Win != 1)
       {
          ... //Your main code
       }
       return 0;
    }
    This will run your code until Win gets the value 1.

    And DON'T use goto, it is easily abused .
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    2
    It's not part of a loop and I don't feel like changing all the code just to make it part of the loop

    that's why I want to use a goto

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>stupid question need quick answer
    ... then read this first.

    Like Magos said, avoid the use of goto.

    >>It's not part of a loop
    Then what's it part of? If you're knee deep in functions, you can always return your way back. Why not post some code (or maybe pseudo code) showing your design, that way someone can advise you better.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by mbsupermario
    It's not part of a loop and I don't feel like changing all the code just to make it part of the loop

    that's why I want to use a goto
    No loop? So you've written special code for every possible layout? Now that's really inconvenient and bad way of coding...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Hi
    I have only one remark the function exit(0) is in the cstdlib header file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick question about types...
    By Elysia in forum C++ Programming
    Replies: 32
    Last Post: 12-07-2008, 05:39 AM
  2. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  3. One quick question...
    By Kross7 in forum C++ Programming
    Replies: 10
    Last Post: 04-13-2007, 09:50 PM
  4. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM