Problems occured while designing grids (included sfml)

The designation is that I want to design a 3*3 big grids which have 3*3 small grids inside the big grids,that means there are 81 small grids equally distributed in 9 big grids.

But now the first column of small grids in the third big grid is missing, although I have reset the yPosition value. What's the problem?

The code of my program are as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <SFML/Graphics.hpp>

using namespace std;

int main()
{
    const int gridSize = 3;
    const int gridCellSize = 50;
    int xPosition1 = 0;
    int yPosition1 = 50;
    int xPosition2 = 0;
    int yPosition2;
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
    sf::RectangleShape shape;
    shape.setSize (sf::Vector2f(50, 50));
    shape.setOutlineColor(sf::Color::Black);
    shape.setOutlineThickness(2);
    shape.setFillColor(sf::Color::Yellow);
    for (int i = 0; i<gridSize; i++)
    {
        for(int j = 0; j<gridSize; j++)
        {
            for (int m = 0; m<gridSize; m++)
            {
                for (int n = 0; n<gridSize; n++)
                {
                    shape.setPosition(xPosition1, yPosition1);
                    window.draw(shape);
                    xPosition1 += gridCellSize;
                }
                xPosition1 = 0 + xPosition2;
                yPosition1 += gridCellSize;

            }
        yPosition1 += 10;

        }
    yPosition1 = 50;
    xPosition2 = xPosition1 + 160;
    }
    window.display();
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
        }
    }

}
Topic archived. No new replies allowed.