Since you are working with a console GUI, I suggest using some kind of cursor movement function. It will also save you a lot of time aligning “objects”.
Here is the code that you will need to move the cursor for 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 any of them if you do not need independence from the platform, but at the same time they will not harm either. 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(); }
Writing and reading are now independent of each other, and you can also go around all positions much easier.
source share