Thread: restricting code from printing

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    44

    restricting code from printing

    i am trying to stop a piece of code from printing when there is something already in a cell of a grid

    Code:
    for(int d = 0; d <DEPTH; d++){
    			for(int r = 0; r<ROW; r++){
    				for(int c = 0; c< COL; c++)
    				{
    					if(!array[d][r][c].getMarked())
    					{
    						
    						array[currentDepth][currentRow][currentCol].mark(player);
    						return;
    					}
    					else
    						cout << "Space already occupied by a player choose another. " << endl;
    						
    						return;
    				}
    			}
    		}
    					
    		break;
    what i am trying to do is if the cell in the grid is marked by a character (player) i want it to just print the cout statement and not replace the character that is already in it. the getMarked() is a bool statement to see if there is a character in the cell. it simply returns the players symbol. the mark(player) marks the cell that you are in with the players character. what it does right now is prints the character even if there is wone already in there and does not display the cout message i am so close to gettin it i know it but i cant any help would be great.
    Last edited by tunerfreak; 04-04-2006 at 11:51 AM.

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    maybe like this?

    Code:
    if(array[d][r][c].getMarked() != true)
    edit: sorry, I read too fast!
    Last edited by Ideswa; 04-05-2006 at 07:40 AM.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    He said it was bool. The thing I'm suspicious about is why you're using three different int variables in your subscripts when you're marking. Shouldn't you be marking the one you checked and returned false?
    Sent from my iPadŽ

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    44
    it returns a bool marked

    Code:
    bool getMarked() {return marked;}
    Code:
    void Cell::mark(Player *player)
    {
    	marked = true;
    	this->player = player;
    }
    
    char Cell::draw () {
    	if(active) return ACTIVE;
    	if(marked) return player->getMark();
    	return ' ';
    }
    marked starts off as false

    Code:
    Cell::Cell()
    {
    	marked = false;
    	active = false;
    }

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    44
    Quote Originally Posted by SlyMaelstrom
    He said it was bool. The thing I'm suspicious about is why you're using three different int variables in your subscripts when you're marking. Shouldn't you be marking the one you checked and returned false?
    u mean array[d][r][c].getMarked ? im not marking with that its just checking of the cell im in is marked by a player. i mark with array[currentDepth][currentRow][currentCol].mark(player)

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    44
    so after a little testing i found out that what i really did there was stop printing if a player has won although it dont work perfectly though so now i dont know how to stop it from printing if there is someone there

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by tunerfreak
    u mean array[d][r][c].getMarked ? im not marking with that its just checking of the cell im in is marked by a player. i mark with array[currentDepth][currentRow][currentCol].mark(player)
    Exactly, why are you checking one thing and then marking another?

    That's like saying the kitchen is clear, there for there must not be anyone in the dining room. From what it seems, the current variables are what you are trying to mark from the beginning, then why are you looping to check all the other spots? Just check that one spot.
    Sent from my iPadŽ

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    44
    so it should be something like

    Code:
    if(!array[currentDepth][currentRow][currentCol].getMarked())
    or something along that order.

    EDIT:

    yup thats it, i just threw that in there and it worked perfect thx
    Last edited by tunerfreak; 04-04-2006 at 10:16 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM