Help me please - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help me please

cuongmitscuongmits Posts: 34Member
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.
[code]
#include
#include
#include
#include
#include

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
", 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;
}
[/code]

Comments

  • Gregry2Gregry2 Posts: 607Member
    [b][red]This message was edited by Gregry2 at 2006-3-29 14:7:52[/red][/b][hr]
    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.
    : [code]
    : #include
    : #include
    : #include
    : #include
    : #include
    :
    : 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();[red]/*I noticed that errorcode has
    no type. Is it an external variable?*/[/red]
    : if (errorcode != grOk) /* an error occurred */
    : {
    : printf("Graphics error: %s
    ", 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;
    : }
    : [/code]
    :



  • shaolin007shaolin007 Posts: 1,018Member
    : 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.
    : [code]
    : #include
    : #include
    : #include
    : #include
    : #include
    :
    : 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
    ", 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;
    : }
    : [/code]
    :

    [green]
    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?
    [/green]

  • LundinLundin Posts: 3,711Member
    : 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.
    : [code]
    : #include
    : #include
    : #include
    : #include
    : #include
    :
    : 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
    ", 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;
    : }
    : [/code]
    :


    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:

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

    numberStr[i]='';
    [/code]

    You will need to add error handling: check "i" so that the buffer numberStr doesn't overflow etc etc.
  • cuongmitscuongmits Posts: 34Member
    : : 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.
    : : [code]
    : : #include
    : : #include
    : : #include
    : : #include
    : : #include
    : :
    : : 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
    ", 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;
    : : }
    : : [/code]
    : :
    :
    :
    : 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:
    :
    : [code]
    : char numberStr[20];
    : outtextxy(some_x, some_y, "Enter number:");
    : do
    : {
    : numberStr[i]=getch();
    : numberStr[i+1]='';
    : outtextxy(some_x + offset + something*i, some_y, &numberStr[i]);
    : }while(isdigit(numberStr[i++]));
    :
    : numberStr[i]='';
    : [/code]
    :
    : 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 :)
Sign In or Register to comment.