Please help

Hello, I have this simple 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
#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
        float x, y;

	cout << "Enter x coordinate: ";
	cin >> x;
	cout << "Enter y coordinate: ";
	cin >> y;

	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t-------------------------------" << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;
	cout << "\t\t\t\t      |      " << endl;

	COORD point;
	point.X = x;
	point.Y = y;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), point);
	cout << "x";


        int i = 0;
	cin >> i; 
	return 0;
}


Basically I am trying to find a way to plot the x in its respective quadrant based on the user's input. How can I achieve this please?
Last edited on
Paint on a canvas in memory and then print the canvas, perhaps?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
struct canvas
{
    static constexpr std::size_t MAXV = 20 ;
    std::string x_axis = std::string( MAXV*2 + 1, '-' ) ;
    std::string line = std::string( MAXV, ' ' ) + '|' + std::string( MAXV, ' ' ) ;

    canvas() : pixels( MAXV*2 + 1, line ) { pixels[MAXV] = x_axis ; }

    void put_pixel( int x, int y )
    {
        const std::size_t col = x + MAXV ;
        const std::size_t row = y + MAXV ;
        if( col < pixels[0].size() && row < pixels.size() ) pixels[row][col] = 'X' ;
    }

    std::vector<std::string> pixels ;
};

std::ostream& operator<< ( std::ostream& stm, const canvas& c )
{
    for( const std::string& str : c.pixels ) stm << str << '\n' ;
    return stm << '\n' ;
}

http://coliru.stacked-crooked.com/a/79228b3e1ff0f84d
You have not adjusted for coordinate systems.

   - The console coordinate system places (0,0) as the upper-left character.
   - The displayed coordinate system places (0,0) at (38, unknown) in the console coordinate system.

The reason that the y coordinate is unknown is that you do not know the number of lines displayed above your program's start on the console. In order to solve this problem you have several options -- the simplest two being:

   - Follow JLBorges's advice and do all drawing in memory first
   - Clear the screen before drawing

http://www.cplusplus.com/articles/4z18T05o/

Good luck!
Topic archived. No new replies allowed.