Thread: Swapping positions of random number in Arrays

  1. #16
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The problem is, you've hard coded this, into your game:
    Code:
    puzzle[row][col] = '#';
    Which obviously won't work out when you have "flipped" the char's you want to display.

    Make a variable of type char, and set that char variable to '#', or to 'Y' or whatever you want to flip your char's to.

    And always print out the board, using

    Code:
    puzzle[row][col] = charVariable;
    instead of any one particular char.

  2. #17
    Registered User l2krence's Avatar
    Join Date
    Nov 2010
    Posts
    24
    @@@@@@@@@@@@@@@@@@@@@@@@@@
    bumps bumps
    Last edited by l2krence; 11-17-2010 at 09:10 PM.

  3. #18
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    LOL, HIT2080?
    Which class are you in?
    Anyway, to remain 2 tiles stay open, just keep track of the flip count, you only reset it to "close" tile after 2 tiles has been flipped. So basicly, if you want to do it in a more efficient way, you should have a flip attribute in your struct to indicate that whether the tile is flipped or not. for e.g., the "!" is currently at location array[3][4], then u set array[3][4].flip = 1, to indicate that this tile is flipped. Then you increment the flipcount. The next tile, you flip again, let say array[4][4], then you set array[4][4].flip = 1, increment flipcount.
    Now flipcount = 2. so the next step in your loop, you just use a for loop to set all tile's flip to 0 for instance array[i][j].flip = 0. then the next time you print the board, if(array[i][j].flip!=1) printf("#"); else { printf( REAL CHAR VAL HERE) }
    Last edited by wejnc; 11-17-2010 at 03:55 AM. Reason: miss a statement

  4. #19
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    I dont really know what were you asking about the "!", but the "!" is just for showing, you dont need to create an extra array or even variable to show this sign. You should had 2 variable to indicate x and y position of the board.
    Let say x is for row and y is for col, x = y = 0 by default, so your "!" will be at location 0,0 by default. When you move, you update your x or y location. Thats how you make "!" move.
    If you have a problem of having the two flipped tile showed on the screen, refer to my last reply, and make sure the order of your system("cls") and reprinting the board is correct, then it shall work fine. The assignmenmt due on fri, all the best!

  5. #20
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    for(r=0;r<ROWS;r++) {
    for(c=0;c<COLS;c++) {
    grid[r][c]='#';
    }
    }
    grid[0][0]='!';
    This will make your code complicated. You do not assign # and ! to your array, just print it out as # and !. the grid array should have the real random pairs for char and not '#' or '!'

  6. #21
    Registered User l2krence's Avatar
    Join Date
    Nov 2010
    Posts
    24
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    thx
    Last edited by l2krence; 11-17-2010 at 09:10 PM.

  7. #22
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    hehe, I am not a student, I am one of the tutor. But you really need to tell me which class are you in and who is your tutor, so that I know what kind of info I can give you. Let me know which steps you had done. Moving the "!", flipping correctly? Make sure you done all those first before you continue to matching.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random number problems
    By lespaul5895 in forum C Programming
    Replies: 3
    Last Post: 07-05-2007, 02:16 AM
  2. Counting number from a random file
    By kamisama in forum C Programming
    Replies: 42
    Last Post: 02-22-2005, 05:16 PM
  3. random number
    By mrukok in forum C++ Programming
    Replies: 7
    Last Post: 03-16-2003, 08:04 PM
  4. Random number generator
    By Caze in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2002, 08:10 AM
  5. Ask about generate Random number
    By ooosawaddee3 in forum C Programming
    Replies: 2
    Last Post: 07-01-2002, 04:30 AM