VS Express dosen't compile the code properly (?) : <p>So I used to use Code::Blocks IDE, and like it a lot. Recently I switched to Visual Studio. I downloaded VS Express, it was 600mb and I can only use 1gb data per day, I don't have Wi-Fi, so I that was my only option.I inserted the same code that compiled properly in Code::Blocks in it , it took a few tweaks to make it work in VS, but when I finally check it, the output was totally different, Instead of a command line Tetris, it glitched and filled the command prompt with strange characters.</p>

<p>This is the code I tweaked a bit to make it work in VS:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;time.h&gt;
#include &lt;string&gt;
#include &lt;windows.h&gt;
using namespace std;

int nScreenHeight = 30;
int nScreenWidth = 80;
int nFieldWidth = 10;
int nFieldHeight = 25;
unsigned char *pField = NULL;
wstring tetromine[7];

int currentPiece = 0;
int currentRotation = 0;
int currentX = (nFieldWidth/2);
int currentY = 0;
unsigned int score = 0;

int pieceCounter = 0;
int speed = 20;
int speedCounter = 0;
bool forcePieceDown =false;
bool key[4];
bool shiftGridDown = false;

int rotate(int px,int py,int r)
{
    switch(r/90)
    {
    case 0:
        return py*4+px;//0 degs
    case 1:
        return 12+py - (px*4);//90 degs
    case 2:
        return 15 - (py*4) - px;//180 degs
    case 3:
        return 3 - py + (px*4);//270 degs
    }
    return 0;
}

int doesPieceFit(int id,int rot, int x, int y)
{
    for(int px = 0;px&lt;4;px++){
        for(int py = 0;py&lt;4;py++){
            int pi = rotate(px,py,rot);
            int fi = (y+py) * nFieldWidth + (x+px);
            if(x + px&gt;= 0 &amp;&amp; x+px &lt; nFieldWidth){
                if(tetromine[id][pi] == L'X' &amp;&amp; pField[fi]!=0){
                    return false;
                }
            }
        }
    }
    return true;
}

void lineCheck(){
    bool line = true;
    int lines = 0;
    for(int y = 0; y&lt;= nFieldHeight-1;y++){
        for(int x = 1; x&lt; nFieldWidth-1;x++){
            if(pField[(y)*nFieldWidth+x]!=0){
                line &amp;= true;
            } else line &amp;= false;
        }
        if(line) lines++;
        if(line){
            for(int x = 1; x&lt; nFieldWidth-1;x++){
                pField[(y)*nFieldWidth+x] = 8;
            }
        }
    }
}


int main()
{

    //assets
    tetromine[0].append(L"..X.");
    tetromine[0].append(L"..X.");
    tetromine[0].append(L"..X.");
    tetromine[0].append(L"..X.");

    tetromine[1].append(L"..X.");
    tetromine[1].append(L".XX.");
    tetromine[1].append(L".X..");
    tetromine[1].append(L"....");

    tetromine[2].append(L".X..");
    tetromine[2].append(L".XX.");
    tetromine[2].append(L"..X.");
    tetromine[2].append(L"....");

    tetromine[3].append(L"....");
    tetromine[3].append(L".XX.");
    tetromine[3].append(L".XX.");
    tetromine[3].append(L"....");

    tetromine[4].append(L"..X.");
    tetromine[4].append(L".XX.");
    tetromine[4].append(L"..X.");
    tetromine[4].append(L"....");

    tetromine[5].append(L"....");
    tetromine[5].append(L".XX.");
    tetromine[5].append(L"..X.");
    tetromine[5].append(L"..X.");

    tetromine[6].append(L"....");
    tetromine[6].append(L".XX.");
    tetromine[6].append(L".X..");
    tetromine[6].append(L".X..");

    pField = new unsigned char[nFieldWidth*nFieldHeight];
    for(int x = 0; x&lt;nFieldWidth; x++)
    {
        for(int y = 0; y&lt;nFieldHeight; y++)
        {
            pField[y*nFieldWidth + x] = (x==0||x==nFieldWidth -1 || y == nFieldHeight - 1) ? 9 : 0;
        }
    }

    char *screen = new char [nScreenWidth * nScreenHeight];
    HANDLE hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
    SetConsoleActiveScreenBuffer(hConsole);
    DWORD dwBytesWritten = 0;

    //Display frame
    COORD here;
    here.X = 0;
    here.Y = 0;
    WriteConsoleOutputCharacter(hConsole, (LPCWSTR)screen, nScreenWidth * nScreenHeight,here, &amp;dwBytesWritten);

    bool gameOver = false;

    while(!gameOver)
    {
        Sleep(100);
        speedCounter++;
        if(speedCounter&gt;=speed){
            forcePieceDown = true;
            speedCounter = 0;
        } else {
            forcePieceDown = false;
        }

        if(shiftGridDown){
            score++;
            for(int y = nFieldHeight-2;y &gt; 0;y--){
                for(int x = 1;x&lt;nFieldWidth -1;x++){
                    if((pField[(y)*nFieldWidth+x]) != 0){
                        pField[(y+1)*nFieldWidth+x] = pField[(y)*nFieldWidth+x];
                        pField[(y)*nFieldWidth+x] = 0;
                    }
                }
            }
            shiftGridDown = false;
            lineCheck();
        }

        for(int x = 1; x&lt; nFieldWidth-1;x++){
            if(pField[(nFieldHeight-2)*nFieldWidth+x]==8){
                pField[(nFieldHeight-2)*nFieldWidth+x]=0;
                if(x==nFieldWidth-2){
                    shiftGridDown = true;
                    score+=100;
                }
            }
        }

        for(int k = 0;k&lt;4;k++){                              //  R   L   D  Z
            key[k] = (0x8000 &amp; GetAsyncKeyState((unsigned char)("DASZ"[k]))) != 0;
        }
        if(key[1]){
            if(doesPieceFit(currentPiece,currentRotation,currentX-1,currentY)){
                currentX = currentX-1;
            }
        }else if(key[0]){
            if(doesPieceFit(currentPiece,currentRotation,currentX+1,currentY)){
                currentX = currentX+1;
            }
        }if(key[2]){
            speedCounter = speed;
        }
        if(key[3]&amp;&amp;doesPieceFit(currentPiece,currentRotation+90,currentX,currentY)){
            (currentRotation+90&lt;=270)?currentRotation+=90:currentRotation=0;
        }

        if(forcePieceDown){
            if(doesPieceFit(currentPiece,currentRotation,currentX,currentY+1))
                currentY++;
            else {
                //lock piece
                pieceCounter++;
                if(pieceCounter%5==0){
                    speed-=1;
                }
                for(int px = 0;px&lt;4;px++){
                    for(int py = 0;py&lt;4;py++){
                        if(tetromine[currentPiece][rotate(px,py,currentRotation)]==L'X'){
                            pField[(currentY+py)*nFieldWidth+(currentX+px)] = currentPiece+1;
                        }
                    }
                }
                score+=20;
                //check lines
                lineCheck();

                //get next piece
                currentX = nFieldWidth/2;
                currentY = 0;
                currentRotation = 0;
                srand(time(0));
                currentPiece = rand() % 7;

                //check game over
                gameOver = !doesPieceFit(currentPiece,currentRotation,currentX,currentY);
            }
        }

        //draw field
        for(int x = 0; x &lt; nFieldWidth; x++)
        {
            for(int y = 0; y &lt; nFieldHeight; y++)
            {
                screen[(y+2)*nScreenWidth + (x+  2)] = L" xxxxxxx=#"[pField[y*nFieldWidth + x]];
            }
        }

        //draw piece
        for(int px = 0;px&lt;4;px++){
            for(int py = 0;py&lt;4;py++){
                    if(tetromine[currentPiece][rotate(px,py,currentRotation)] == L'X'){
                        screen[(currentY+py+2)*nScreenWidth+(currentX+px+2)] = '+';
                    }
            }
        }
        string s("Score -&gt; ");
        string num;
        int tmp = score;
        while(tmp!=0){
            int rem = tmp%10;
            tmp /= 10;
            num = ((char)(48+rem)) + num;
        }
        s+=num;
        for(int i = 0; i&lt;s.size();i++){
            screen[i] = s[i];
        }

        //display frame
        WriteConsoleOutputCharacter(hConsole, (LPCWSTR)screen, nScreenWidth * nScreenHeight,here, &amp;dwBytesWritten);
    }

    return 0;
}
</code></pre>

<p>This is the origional code :</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;time.h&gt;
#include &lt;string&gt;
#include &lt;windows.h&gt;
using namespace std;

int nScreenHeight = 30;
int nScreenWidth = 80;
int nFieldWidth = 10;
int nFieldHeight = 25;
unsigned char *pField = NULL;
wstring tetromine[7];

int currentPiece = 0;
int currentRotation = 0;
int currentX = (nFieldWidth/2);
int currentY = 0;
unsigned int score = 0;

int pieceCounter = 0;
int speed = 20;
int speedCounter = 0;
bool forcePieceDown =false;
bool key[4];
bool shiftGridDown = false;

int rotate(int px,int py,int r)
{
    switch(r/90)
    {
    case 0:
        return py*4+px;//0 degs
    case 1:
        return 12+py - (px*4);//90 degs
    case 2:
        return 15 - (py*4) - px;//180 degs
    case 3:
        return 3 - py + (px*4);//270 degs
    }
    return 0;
}

int doesPieceFit(int id,int rot, int x, int y)
{
    for(int px = 0;px&lt;4;px++){
        for(int py = 0;py&lt;4;py++){
            int pi = rotate(px,py,rot);
            int fi = (y+py) * nFieldWidth + (x+px);
            if(x + px&gt;= 0 &amp;&amp; x+px &lt; nFieldWidth){
                if(tetromine[id][pi] == L'X' &amp;&amp; pField[fi]!=0){
                    return false;
                }
            }
        }
    }
    return true;
}

void lineCheck(){
    bool line = true;
    int lines = 0;
    for(int y = 0; y&lt;= nFieldHeight-1;y++){
        for(int x = 1; x&lt; nFieldWidth-1;x++){
            if(pField[(y)*nFieldWidth+x]!=0){
                line &amp;= true;
            } else line &amp;= false;
        }
        if(line) lines++;
        if(line){
            for(int x = 1; x&lt; nFieldWidth-1;x++){
                pField[(y)*nFieldWidth+x] = 8;
            }
        }
    }
}


int main()
{

    //assets
    tetromine[0].append(L"..X.");
    tetromine[0].append(L"..X.");
    tetromine[0].append(L"..X.");
    tetromine[0].append(L"..X.");

    tetromine[1].append(L"..X.");
    tetromine[1].append(L".XX.");
    tetromine[1].append(L".X..");
    tetromine[1].append(L"....");

    tetromine[2].append(L".X..");
    tetromine[2].append(L".XX.");
    tetromine[2].append(L"..X.");
    tetromine[2].append(L"....");

    tetromine[3].append(L"....");
    tetromine[3].append(L".XX.");
    tetromine[3].append(L".XX.");
    tetromine[3].append(L"....");

    tetromine[4].append(L"..X.");
    tetromine[4].append(L".XX.");
    tetromine[4].append(L"..X.");
    tetromine[4].append(L"....");

    tetromine[5].append(L"....");
    tetromine[5].append(L".XX.");
    tetromine[5].append(L"..X.");
    tetromine[5].append(L"..X.");

    tetromine[6].append(L"....");
    tetromine[6].append(L".XX.");
    tetromine[6].append(L".X..");
    tetromine[6].append(L".X..");

    pField = new unsigned char[nFieldWidth*nFieldHeight];
    for(int x = 0; x&lt;nFieldWidth; x++)
    {
        for(int y = 0; y&lt;nFieldHeight; y++)
        {
            pField[y*nFieldWidth + x] = (x==0||x==nFieldWidth -1 || y == nFieldHeight - 1) ? 9 : 0;
        }
    }

    char *screen = new char [nScreenWidth * nScreenHeight];
    HANDLE hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
    SetConsoleActiveScreenBuffer(hConsole);
    DWORD dwBytesWritten = 0;

    //Display frame

    WriteConsoleOutputCharacter(hConsole, screen, nScreenWidth * nScreenHeight, {0,0}, &amp;dwBytesWritten);

    bool gameOver = false;

    while(!gameOver)
    {
        Sleep(100);
        speedCounter++;
        if(speedCounter&gt;=speed){
            forcePieceDown = true;
            speedCounter = 0;
        } else {
            forcePieceDown = false;
        }

        if(shiftGridDown){
            score++;
            for(int y = nFieldHeight-2;y &gt; 0;y--){
                for(int x = 1;x&lt;nFieldWidth -1;x++){
                    if((pField[(y)*nFieldWidth+x]) != 0){
                        pField[(y+1)*nFieldWidth+x] = pField[(y)*nFieldWidth+x];
                        pField[(y)*nFieldWidth+x] = 0;
                    }
                }
            }
            shiftGridDown = false;
            lineCheck();
        }

        for(int x = 1; x&lt; nFieldWidth-1;x++){
            if(pField[(nFieldHeight-2)*nFieldWidth+x]==8){
                pField[(nFieldHeight-2)*nFieldWidth+x]=0;
                if(x==nFieldWidth-2){
                    shiftGridDown = true;
                    score+=100;
                }
            }
        }

        for(int k = 0;k&lt;4;k++){                              //  R   L   D  Z
            key[k] = (0x8000 &amp; GetAsyncKeyState((unsigned char)("DASZ"[k]))) != 0;
        }
        if(key[1]){
            if(doesPieceFit(currentPiece,currentRotation,currentX-1,currentY)){
                currentX = currentX-1;
            }
        }else if(key[0]){
            if(doesPieceFit(currentPiece,currentRotation,currentX+1,currentY)){
                currentX = currentX+1;
            }
        }if(key[2]){
            speedCounter = speed;
        }
        if(key[3]&amp;&amp;doesPieceFit(currentPiece,currentRotation+90,currentX,currentY)){
            (currentRotation+90&lt;=270)?currentRotation+=90:currentRotation=0;
        }

        if(forcePieceDown){
            if(doesPieceFit(currentPiece,currentRotation,currentX,currentY+1))
                currentY++;
            else {
                //lock piece
                pieceCounter++;
                if(pieceCounter%5==0){
                    speed-=1;
                }
                for(int px = 0;px&lt;4;px++){
                    for(int py = 0;py&lt;4;py++){
                        if(tetromine[currentPiece][rotate(px,py,currentRotation)]==L'X'){
                            pField[(currentY+py)*nFieldWidth+(currentX+px)] = currentPiece+1;
                        }
                    }
                }
                score+=20;
                //check lines
                lineCheck();

                //get next piece
                currentX = nFieldWidth/2;
                currentY = 0;
                currentRotation = 0;
                srand(time(0));
                currentPiece = rand() % 7;

                //check game over
                gameOver = !doesPieceFit(currentPiece,currentRotation,currentX,currentY);
            }
        }

        //draw field
        for(int x = 0; x &lt; nFieldWidth; x++)
        {
            for(int y = 0; y &lt; nFieldHeight; y++)
            {
                screen[(y+2)*nScreenWidth + (x+  2)] = L" xxxxxxx=#"[pField[y*nFieldWidth + x]];
            }
        }

        //draw piece
        for(int px = 0;px&lt;4;px++){
            for(int py = 0;py&lt;4;py++){
                    if(tetromine[currentPiece][rotate(px,py,currentRotation)] == L'X'){
                        screen[(currentY+py+2)*nScreenWidth+(currentX+px+2)] = '+';
                    }
            }
        }
        string s("Score -&gt; ");
        string num;
        int tmp = score;
        while(tmp!=0){
            int rem = tmp%10;
            tmp /= 10;
            num = ((char)(48+rem)) + num;
        }
        s+=num;
        for(int i = 0; i&lt;s.size();i++){
            screen[i] = s[i];
        }

        //display frame
        WriteConsoleOutputCharacter(hConsole, screen, nScreenWidth * nScreenHeight, { 0, 0}, &amp;dwBytesWritten);
    }

    return 0;
}
</code></pre>
