C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28630
Number of posts: 94612

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help me please Posted by cuongmits on 29 Mar 2006 at 11:59 AM
how to get the right position of showing entered value?
Please run this program, you will se the problem with the position of the value that you enter.
I dont know how to fix it :(
Help me plz.
#include <iostream.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "");

   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   }

   int a;

   outtextxy(100,50,"enter number: "); //
   gotoxy(100,70);
   cin >> a;           //I want this value to be shown in a right place
                       //for example:
                       //enter number: 1111


   /* clean up */
   getch();
   closegraph();
   return 0;
}

Report
Re: Help me please <others, reply to above> Posted by Gregry2 on 29 Mar 2006 at 2:06 PM
This message was edited by Gregry2 at 2006-3-29 14:7:52

I don't use DOS, so I can't help you, I only noticed one thing...

: how to get the right position of showing entered value?
: Please run this program, you will se the problem with the position of the value that you enter.
: I dont know how to fix it :(
: Help me plz.
:
: #include <iostream.h>
: #include <graphics.h>
: #include <stdlib.h>
: #include <stdio.h>
: #include <conio.h>
: 
: int main(void)
: {
:    /* request auto detection */
:    int gdriver = DETECT, gmode, errorcode;
: 
:    /* initialize graphics and local variables */
:    initgraph(&gdriver, &gmode, "");
: 
:    /* read result of initialization */
:    errorcode = graphresult();/*I noticed that errorcode has
 no type. Is it an external variable?*/
:    if (errorcode != grOk)  /* an error occurred */
:    {
:       printf("Graphics error: %s\n", grapherrormsg(errorcode));
:       printf("Press any key to halt:");
:       getch();
:       exit(1); /* terminate with an error code */
:    }
: 
:    int a;
: 
:    outtextxy(100,50,"enter number: "); //
:    gotoxy(100,70);
:    cin >> a;           //I want this value to be shown in a right place
:                        //for example:
:                        //enter number: 1111
: 
: 
:    /* clean up */
:    getch();
:    closegraph();
:    return 0;
: }
: 

:



Report
Re: Help me please Posted by shaolin007 on 29 Mar 2006 at 8:38 PM
: how to get the right position of showing entered value?
: Please run this program, you will se the problem with the position of the value that you enter.
: I dont know how to fix it :(
: Help me plz.
:
: #include <iostream.h>
: #include <graphics.h>
: #include <stdlib.h>
: #include <stdio.h>
: #include <conio.h>
: 
: int main(void)
: {
:    /* request auto detection */
:    int gdriver = DETECT, gmode, errorcode;
: 
:    /* initialize graphics and local variables */
:    initgraph(&gdriver, &gmode, "");
: 
:    /* read result of initialization */
:    errorcode = graphresult();
:    if (errorcode != grOk)  /* an error occurred */
:    {
:       printf("Graphics error: %s\n", grapherrormsg(errorcode));
:       printf("Press any key to halt:");
:       getch();
:       exit(1); /* terminate with an error code */
:    }
: 
:    int a;
: 
:    outtextxy(100,50,"enter number: "); //
:    gotoxy(100,70);
:    cin >> a;           //I want this value to be shown in a right place
:                        //for example:
:                        //enter number: 1111
: 
: 
:    /* clean up */
:    getch();
:    closegraph();
:    return 0;
: }
: 

:


What exactly is it doing? I can't compile your program because you use borland graphics library which I don't have. What mode are you in? Is it 80x25 16 color text mode?


Report
Re: Help me please Posted by Lundin on 29 Mar 2006 at 11:18 PM
: how to get the right position of showing entered value?
: Please run this program, you will se the problem with the position of the value that you enter.
: I dont know how to fix it :(
: Help me plz.
:
: #include <iostream.h>
: #include <graphics.h>
: #include <stdlib.h>
: #include <stdio.h>
: #include <conio.h>
: 
: int main(void)
: {
:    /* request auto detection */
:    int gdriver = DETECT, gmode, errorcode;
: 
:    /* initialize graphics and local variables */
:    initgraph(&gdriver, &gmode, "");
: 
:    /* read result of initialization */
:    errorcode = graphresult();
:    if (errorcode != grOk)  /* an error occurred */
:    {
:       printf("Graphics error: %s\n", grapherrormsg(errorcode));
:       printf("Press any key to halt:");
:       getch();
:       exit(1); /* terminate with an error code */
:    }
: 
:    int a;
: 
:    outtextxy(100,50,"enter number: "); //
:    gotoxy(100,70);
:    cin >> a;           //I want this value to be shown in a right place
:                        //for example:
:                        //enter number: 1111
: 
: 
:    /* clean up */
:    getch();
:    closegraph();
:    return 0;
: }
: 

:


gotoxy() is for the DOS-prompt, so it will only accept values up to (80, 25).

You can mix cin with the BGI graphics but it won't be pretty.
Best way is to use getch() and then echo the typed char back to the screen using outtextxy(). Something like this:

char numberStr[20];
outtextxy(some_x, some_y, "Enter number:"); 
do
{
  numberStr[i]=getch();
  numberStr[i+1]='\0';
  outtextxy(some_x + offset + something*i, some_y, &numberStr[i]);
}while(isdigit(numberStr[i++]));

numberStr[i]='\0';


You will need to add error handling: check "i" so that the buffer numberStr doesn't overflow etc etc.
Report
Re: Help me please Posted by cuongmits on 31 Mar 2006 at 6:37 AM
: : how to get the right position of showing entered value?
: : Please run this program, you will se the problem with the position of the value that you enter.
: : I dont know how to fix it :(
: : Help me plz.
: :
: : #include <iostream.h>
: : #include <graphics.h>
: : #include <stdlib.h>
: : #include <stdio.h>
: : #include <conio.h>
: : 
: : int main(void)
: : {
: :    /* request auto detection */
: :    int gdriver = DETECT, gmode, errorcode;
: : 
: :    /* initialize graphics and local variables */
: :    initgraph(&gdriver, &gmode, "");
: : 
: :    /* read result of initialization */
: :    errorcode = graphresult();
: :    if (errorcode != grOk)  /* an error occurred */
: :    {
: :       printf("Graphics error: %s\n", grapherrormsg(errorcode));
: :       printf("Press any key to halt:");
: :       getch();
: :       exit(1); /* terminate with an error code */
: :    }
: : 
: :    int a;
: : 
: :    outtextxy(100,50,"enter number: "); //
: :    gotoxy(100,70);
: :    cin >> a;           //I want this value to be shown in a right place
: :                        //for example:
: :                        //enter number: 1111
: : 
: : 
: :    /* clean up */
: :    getch();
: :    closegraph();
: :    return 0;
: : }
: : 

: :
:
:
: gotoxy() is for the DOS-prompt, so it will only accept values up to (80, 25).
:
: You can mix cin with the BGI graphics but it won't be pretty.
: Best way is to use getch() and then echo the typed char back to the screen using outtextxy(). Something like this:
:
:
: char numberStr[20];
: outtextxy(some_x, some_y, "Enter number:"); 
: do
: {
:   numberStr[i]=getch();
:   numberStr[i+1]='\0';
:   outtextxy(some_x + offset + something*i, some_y, &numberStr[i]);
: }while(isdigit(numberStr[i++]));
: 
: numberStr[i]='\0';
: 

:
: You will need to add error handling: check "i" so that the buffer numberStr doesn't overflow etc etc.
:
My program is correctly working now
Thanh all :)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.