My Terminal's background color desyncs after too many new lines

23 Views Asked by At

Like I said in my title, after 3 or so iterations of this code, the text background starts to bug out. It kind of looks like how Source games act out of bounds/with no skybox.

I'm using VS 2017, also if it helps I'm on a display resolution of 1280 X 768.

#include <iostream>
#include <windows.h>
using namespace std;
int x;
int main()
{
    labelSTART:
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 6+2*16);
    
    cout << "This is as far as this goes.\nGo back?  0-NO  1-YES\n";
    cin >> x;
    if (x == 1) {
        SetConsoleTextAttribute(hConsole, 1+5*16);
        cout << "Going back...\nProceed with caution!";
        cout << "\n\n\n\n\n\n\n\n\n\n\n";
        goto labelSTART;
    }
    return 0;
}

third iteration of the program and it's consequences

I am making a game in the Terminal and want to use colors and to fully refresh the screen every frame. The problem is that after 2 or so screens the unused space of the terminal gets filled in with the last used background color and messes everything up.

0

There are 0 best solutions below