Like Tree1Likes
  • 1 Post By oogabooga

Coordination in C++

This is a discussion on Coordination in C++ within the C++ Programming forums, part of the General Programming Boards category; Can someone tell me if there is any error in my codes? The compiler is able to compile and run ...

  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
    2,699
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    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
    2,349
    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?
    Code:
    namespace life
    {
        const bool change = true;
    }

  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:
    Name:  Untitled.png
Views: 123
Size:  21.8 KB

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    2,349
    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.
    Code:
    namespace life
    {
        const bool change = true;
    }

  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".)
    Salem likes this.
    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, 07:24 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21