: : 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 :)