1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
void ClearScreen(); // Forgot to add in declare. Had function before main()
// but changed it after pasting.
int main()
{
char command = '=';
// string outChar(50,command); Remove. Don't need here.
do {
string outChar(50,command);
cout << outChar << endl;
cout << "Menu Design. Select An Option, or Enter 5 to Quit." << endl;
cout << "1: O" << endl;
cout << "2: !" << endl;
cout << "3: ." << endl;
cout << "4: *" << endl;
cout << "5: Quit" << endl;
cout << "Your Selection: " << endl;
cout << outChar << endl;
cin >> command;
ClearScreen(); // Use instead of a system call
switch (command)
{
case '1':
command = 'O';
break;
case '2':
command = '!';
break;
case '3':
command = '.';
break;
case '4':
command = '*';
break;
case '5':
return 0;
break;
default:
cout<< "Bad input." << endl;
}
} while(command!='5');
cin.get();
cin.ignore();
}
void ClearScreen()
{
DWORD n;
DWORD size;
COORD coord = {0};
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
GetConsoleScreenBufferInfo ( h, &csbi );
size = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
GetConsoleScreenBufferInfo ( h, &csbi );
FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
SetConsoleCursorPosition ( h, coord );
}
|