Thread: Coordination in C++

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    11

    Question Coordination in C++

    Can someone tell me if there is any error in my codes?
    The compiler is able to compile and run the program
    but I can't get the result I want.

    Please help me.

    I am using a gotoxy function.
    I want to output a "@" character on a particular coordinate.

    Here are my codes:
    Code:
    #include <cstdlib>#include <iostream>
    #include<windows.h>
    
    
    using namespace std;
    
    
        void gotoxy (int x, int y)
        {
             COORD coordination;
             coordination.X = x;
             coordination.Y = y;
             SetConsoleCursorPosition(HANDLE(STD_OUTPUT_HANDLE),coordination);
        };
        
    int main()
    {
        int x;
        int y;
        char w = '@'; 
           
        cout<<"Enter x: ";
        cin>>x;
        cout<<"Enter y: ";
        cin>>y;
           
        gotoxy(x,y); 
        cout<<w;
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Can someone tell me if there is any error in my codes?
    The compiler is able to compile and run the program
    but I can't get the result I want.
    You've answered your own question, no the program is not correct if you're not getting the result you want.

    Now as to the actual problem you'll need to tell us what result your program is producing and exactly what output you want your program to produce.


    Jim

  3. #3
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    The main problem is that this program is not C++.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It IS C++, albeit it users Win32 API, too.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    11
    Now as to the actual problem you'll need to tell us what result your program is producing and exactly what output you want your program to produce.
    For example, I want to output @ on coordination (5,5). That's the objective of this program.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by iluvcake View Post
    For example, I want to output @ on coordination (5,5). That's the objective of this program.
    and what happens when you try to do that?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  7. #7
    Registered User
    Join Date
    Apr 2013
    Posts
    11
    and what happens when you try to do that?
    @ was not output exactly where I wanted it to be.
    Here's the sample of the output:
    Coordination in C++-untitled-png

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    my guess is that windows cursor positioning does not play nice with C++ stream I/O. you may need to use Win32 API functions to print characters on the screen after positioning the cursor.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  9. #9
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You've cast away your problem.
    STD_OUTPUT_HANDLE is not a "HANDLE".
    It's an input parameter to GetStdHandle.
    It should be:
    Code:
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coordination);

    (BTW, it's usually called a "coordinate" not a "coordination".)
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-11-2010, 10:16 AM
  2. Replies: 1
    Last Post: 12-01-2009, 08:24 AM

Tags for this Thread