i think i did a decent job, can you please check?

Posted by shaynjam@reddit | learnprogramming | View on Reddit | 11 comments

this is a question gemini generated for me.

The Scenario: You are building a Tetris clone or a top-down game. You have a 3x3 block (a 2D array of numbers). The player hits the "Rotate" button. You need to rotate the entire grid 90 degrees clockwise.

example:

starting-> 1 2 3
4 5 6
7 8 9

after rotation-> 7 4 1
8 5 2
9 6 3

heres my programme for it:

#include <iostream>
using namespace std ;


int main()
{
    int x=0 ;
    char opinion = 'a' ;
    int store[9];
    int m=0;


    int textureMap[3][3]=
    {
        {1, 2, 3},
        {4, 5, 6},
        {7, 8, 9},
    };


    for ( int i =0 ; i < 3 ; i++)
    {
        for (int j = 0 ; j<3 ; j++)
        {
            cout << textureMap[i][j]<< " ";
        }
        cout<< endl ;
    }
    cout << endl ;
     
    cout<< " do you wanna rotate?(Y/N): ";
    std::cin>> opinion ;


    if (opinion == 'Y' || opinion == 'y')
    {
        for ( int a =0 ; a <3  ; a++)
        {
            for (int b = 2 ; b>=0 ; b= b - 1 )
            {   
                store[x] = textureMap[b][a] ;
                x=x+1;
            }
            cout << endl ;
        }
        for ( int i = 0 ; i< 3; i++)
        {
            for (int j = 0 ; j<3 ; j++)
                {
                    {textureMap[i][j] = store[m];}


                    cout << textureMap[i][j]<< " ";
                    
                    m=m+1;
                }
                cout << endl ;
        }
        
       
    }
    std::cin.clear();
    std::cin.ignore(1000, '\n') ;
    std::cin.get();
    return 0 ;
}