So I am making a GUI with ascci, I would like to wait for user input but print the last line of ascci border. As of now it will wait for user input and then print the last ascci border line. Is there anyway to fix this?
Example of what I want:
Login Screen
======================================================
Welcome to Bank Beta 0.1
------------------------
(1)Login
(2)Create Account
USER INPUT HERE
======================================================
Example of what I am getting:
======================================================
Welcome to Bank Beta 0.1
------------------------
(1)Login
(2)Create Account
USER INPUT HERE
Here's my code:
void login ()
{
cout << "======================================================" << endl
<< "\t\tWelcome to Bank Beta 0.1" << endl
<< "\t\t------------------------" << endl << endl
<< "\t\t (1)Login" << endl
<< "\t\t (2)Create Account" << endl << endl;
}
int main()
{
int loginChoice;
login();
cin >> loginChoice;
cout << "======================================================" << endl;
_getch();
}
Since you are working on a console based GUI, i suggest using some sort of cursor movement functionality. This will save you a lot of time in the alignment of "objects" too.
Here is the code you will need to move the cursor for both win and unix
#ifdef _WIN32
#include <windows.h>
void gotoxy(int x, int y)
{
COORD p = { x, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
}
#else
#include <unistd.h>
#include <term.h>
void gotoxy(int x, int y)
{
int err;
if (!cur_term)
if (setupterm(NULL, STDOUT_FILENO, &err) == ERR)
return;
putp(tparm(tigetstr("cup"), y, x, 0, 0, 0, 0, 0, 0, 0));
}
#endif
You can remove either of them if you don't need platform independence, but having them both does no harm. now the interesting part:
void login ()
{
cout << "======================================================" << "\n"
<< "\t\tWelcome to Bank Beta 0.1" << "\n"
<< "\t\t------------------------" << "\n\n"
<< "\t\t (1)Login" << "\n"
<< "\t\t (2)Create Account" << "\n\n";
gotoxy(0, 7);
cout << "======================================================" << "\n";
gotoxy(0, 6);
cout << "\t\t";
}
int main()
{
int loginChoice;
login();
gotoxy(0,8);
cin >> loginChoice;
_getch();
}
The writing and reading are now independent of each other and you can also mess around with all the positions a lot more easyer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With