I am trying to make a program that couts characters in alternating colors.
#include <iostream.h>
#include <windows.h>
#include <dos.h>
#include "Random.h"
void main()
{
randomize();
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
int basecolor1=random(256), basecolor2=random(256);
char board[4][4];
int x, y, k;
for(x=0; x<4; x++)
{
for(y=0; y<4; y++)
{
k=(x%2);
k+=(y%2);
k=k%2;
if(k==1)
{
SetConsoleTextAttribute(hcon,(int)(basecolor1));
//cout<<"l";
}
else
{
SetConsoleTextAttribute(hcon,(int)(basecolor2));
//cout<<"k";
}
//Sleep(1000);
cout<<k;
//cout<<endl;
}
cout<<endl;
}
}
However, only the lines of characters actually alternate.
When you uncomment out the Sleep(1000), which waits for 1 second, the program waits for four seconds then displays the line in one color.
If you uncomment out the cout<<endl, then it displays on a different line, but alternates the colors.
How can I make the program alternate characters and not individual lines?