How can I make function like this?

Hello
I want to make a function like the one that have a comment beside it in this code, to put the cursor in chosen position -----> here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<time.h>
#include<stdlib.h>
using namespace std;

int main()
{
	int x,y,z,n=0,l=5;
	do
	{
	srand( time(NULL) );
	if(n<10)
	{
		 x = rand() % 9+1;
	     y = rand() % 9+1;
	}
	else if( (n>=10)&&(n<20))
	{
		 x = rand() % 89+9;
	     y = rand() % 89+9;
	}
	else if (n>=20)
	{
		cout<<"Congratulation "<<endl;
		break;
	}
	else
		cout<<"Error with n "<<endl;
    wrong:
	cout<<x<<"+"<<y<<"="<<"\t\t\t\t\t Lives("<<l<<")";
	set_cursor_pos(1, 10); // set the cursor position in (height, distance from the line's beginning)
	cin>>z;
	system("cls");
	if(z!= (x+y))
	{
		cout<<"Wrong answer"<<endl;
		l--;
		if(l<0)
		{
			cout<<"Game over"<<endl;
			break;
		}
		goto wrong;
		
	}
	n++;
	}while( z==(x+y) );
	return 0;
}
closed account (10oTURfi)
I see wut u need.
1
2
3
4
5
6
7
void GotoXY(int coordX, int coordY)
{
    COORD coord;
    coord.X = coordX;
    coord.Y = coordY;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

also #include <windows.h> to make it work

but it wont work the way you think it will. go figure how it works.
Last edited on
Krofna !
thank you very much, it works with these coordinates
GotoXY(4, 0)
Last edited on
Topic archived. No new replies allowed.