program exits when it isn't supposed to

This is a discussion on program exits when it isn't supposed to within the C++ Programming forums, part of the General Programming Boards category; Hey all, I'm (still) working on my console-based chess program. I have most of it worked out, but I've run ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    244

    program exits when it isn't supposed to

    Hey all,

    I'm (still) working on my console-based chess program. I have most of it worked out, but I've run across a problem:

    after a few turns, it just exits. (says "Press enter to continue...")

    This is weird because the program is just an infinite loop (for(;) with no way for the program to actually exit (I'm lazy and havn't put in a "Quit?" thing yet).

    Here is the main cpp file:

    Code:
    // chess, main program
    // last updated 10-24-02
    // Will Herrick
    
    #include <iostream>
    #include "board.h"
    
    using namespace std;
    
    int main()
    {
    	int a;
    	int b;
    	int c;
    	int d;
    	int turn;
      bool valid;
      bool check;
    	
    	BOARD board;
    	board.showBoard();
    	board.setTurn(1); // set white first
    	
    	for(;;)
    	{
    		turn = board.getTurn();
    		
    		if(turn == 1) cout << "Whites turn, ";
    		else if(turn == 2) cout << "Blacks turn, ";
    		
    		cout << "Make your move:" << endl;
    		cin >> a >> b >> c >> d;
    		
    		valid = board.Move(a,b,c,d);
    		
      		if(valid == false)
        			cout << "Invalid move" << endl;
      		if(valid == true)
      		{
      			board.showBoard();
      			if(turn == 1) board.setTurn(2);
      			if(turn == 2) board.setTurn(1);
        			check = board.isCheck();
        			if(check == true)
        			{
          				cout << "Check!";
          	  }
    		  }
      	}
    	return 0;
    }
    I'm not posting the other bits (board .cpp) because they are long, but I can do so if necessary.

    What might be a reason for this oddity?

    Thanks!

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Try running it through a debugger?

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    Originally posted by Eibro
    Try running it through a debugger?
    Debuggers are for weaklings!

    Just kidding

    I guess that would be a good idea actually... but I'm going to have to learn how to use gdb in KDevelop :-/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. Pushing enter exits the Program...
    By X01 in forum C++ Programming
    Replies: 6
    Last Post: 05-26-2003, 07:21 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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