help with a grind

This is a discussion on help with a grind within the C++ Programming forums, part of the General Programming Boards category; Hello I got this grid working as you can se in the code bellow, but when i try to make ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    15

    help with a grid

    Hello

    I got this grid working as you can se in the code bellow, but when i try to make some printf (or cout) to make it show some numbers i only get "0 0 1 1 2 2" displayed in a line. anyone know why and how i could make it the display the grid & Numbers like it should?
    Code:
    #include "stdafx.h"
    #include <iostream> 
    #include <ctime> 
    
    using namespace std; 
    
    int main() 
    {
    int grid[3][3]; // grid
    int count = 1;
    
    for(int i = 0; i < 3; i++){
         for(int n = 0; n < 3; n++){
    
              if(i == 2 && n == 2) break; // dont give out a number to square 9
    
              grid[i][n] = count; // give out a number to square 1-8
              count++;
    
    		  cout << i << endl;
    
    		  }
    	
      }
    return 0;
    }
    Last edited by razzaz; 10-02-2008 at 05:46 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You should print out either count, or (more appropriately) grid[i][n], rather than the row number.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    15
    Quote Originally Posted by tabstop View Post
    You should print out either count, or (more appropriately) grid[i][n], rather than the row number.
    if i print out "grid[i][n]" the number become 1,2,3,4,5,6,7,8, and the same with count :/ it is supposed to look someting like this

    http://www.imagefrog.net/out.php/i2912_4.jpg

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That grid also contains the numbers 1 through 8. So?

    (If you haven't noticed that you're printing a new line after every number, instead of after every row, you should do so now.)

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    15
    Quote Originally Posted by tabstop View Post
    That grid also contains the numbers 1 through 8. So?

    (If you haven't noticed that you're printing a new line after every number, instead of after every row, you should do so now.)
    ah sorry i actully did not notice that i printed one new line wich i now removed. How could i make it insteed print the numbers after every row isnteed ? :/

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Instead of printing one endl per number, print one endl per row (you have one for loop that prints each row, so make sure that for loop only has one endl printed in it).

Popular pages Recent additions subscribe to a feed

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