Using gotoxy in a loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
for (int floor = 1; floor <= max_floors; floor++)

	gotoxy(25,1 + floor);
	cout << "Number of rooms on floor " << floor << ":" << endl;
	cin >> number__floor;
	

	// Gathers number of occupied rooms.
	gotoxy(25,2 + floor);
        cout << "Number of occupied rooms: ";
	cin >> occupied_rooms;


}


I am using gotoxy to try and format my input statements for this loop. I took out some code to make it easier on the eyes but i can't seem to figure it out without something overwriting another.

This is the desired display i am trying to achieve:
1
2
3
4
5
6
7
8
9
10
Number of rooms on floor 1: 
Number of occupied rooms:

Number of rooms on floor 2: 
Number of occupied rooms:

Number of rooms on floor 3: 
Number of occupied rooms:

and so on..


Appreciate any input on this issue i am having.

Thanks.


ALSO: Please note that i do have a function created for gotoxy .
Last edited on
What is GotoXY supposed to do, go to a spot in an array?

Can't you just do
1
2
3
4
cout << "Number of rooms: ";
cout << somearray[1][floornumber];
cout << "Number of occupied rooms: ";
cout << somearray[2][floornumber];

I'm not sure about the array format but you should get the idea.
Last edited on
I haven't worked with arrays at all, but gotoxy will go to that specific coordinate on the window and in my case, print the first character of the cout on the specified coordinate.
Last edited on
Oh, so then your problem looks like when you print the first set of data, the data is moved so many coordinates and the second set of data won't be accurate?
Yes that's exactly it, i have tried playing with the coordinates in different ways but i can't seem to get it to be right on. I doubt its a hard fix,i am just overlooking something.
Last edited on
I can't really give you an anwers using GotoXY because Ive never used it.
Is all the data printed on the screen?

I would probobly just use arrays. They are very easy (or at least thats what I think), once you figure out how they work.

Do you know what a matrix is in math? Arrays are extremely similar, they just hold data like text or charactars, and not always numbers.

1
2
3
4
5
6
7
8
9
10
11
12
//I think of arrays as matricies.
//like this:

 int x[5] //this makes an array called "x" that holds 5 integers.
//basically it can hold 5 numbers like this:
x[1]=1;
x[2]=2;
x[3]=3;
x[4]=4;
x[5]=5;

//so now the array equals {1,2,3,4,5}  




The array might start at zero and end at 5 or 4. I don't remember.
Last edited on
Do you know what a matrix is in math? Arrays are extremely similar, they just hold data like text or charactars, and not always numbers.


A matrix in math doesn't always hold numbers either. And saying arrays are similar to matrices is quite a stretch considering arrays don't support a single matrix operation.

Although otherwise I 'll have to agree - it's not quite clear to me why you even use gotoxy to begin with.
@hanst99
Yeah, I never thought of it that way. I never tried using arrays for matrix style math, I thought of them as as matrix looking tables that held data.
Topic archived. No new replies allowed.