#include <iostream>
#include <windows.h>
using namespace std;
int go_to(int x, int y)
{
COORD c;
c.X = x - 1;
c.Y = y - 1;
return SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
}
void main(){
int a=1;
while(a<10){
a++;
cout<<"work"<<endl;
go_to(3,6);
cout<<"work"<<endl;
}
}
I’m not understand why this loop work only 1 time, maybe you know where is problem ?
I thing that problem is in Cord, but don’t know similar way to use CORD.
The variable a is only modified by the
a++;line which increases its value by 1, and it isn’t passed intogo_to(x,y), so it can’t be affected by that function.Your loop will definitely run for values a={1 to 9}, calling
go_to(3, 6)each time, and also printing work twice. I believe you’re mistaken if you think otherwise.