Do while / Switch Menu Design

How do I get outChar underneath the menu as well?
See this for example for Option 4: http://i60.tinypic.com/33onmgx.png

Thank you.

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
#include <iostream>
using namespace std;
int main() {

char command;
char outChar = 0;


do {
		cout << 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: ";
		cin >> command;
		cout << outChar;
		system("cls");
 
 switch (command)
 {
      case '1':
		outChar = 'O';
        cout << outChar;
        break;

	  case '2':
        outChar = '!';
        cout << outChar;
		break; 
     
	 case '3':
		 outChar = '.';
		 cout << outChar;
		break; 
     
	 case '4':
        outChar = '*';
		cout << outChar;
		break; 
    
	case '5':
        return 0;
		break; 

	default:
        cout<< "Bad input." << endl;

    }
 
	for (int i = 0; i < 50; i++) 
	{
		cout << outChar;
	}

} while(command!='5');    

cin.get();
cin.ignore();

} 
Last edited on
You have one double quote too much on line 42.
Thanks! but the desired functionality of the program still doesnt work haha
not sure what you want it to do?
currently it prints out the user selected value 50 times yes? what do you mean by 'underneath the menu'?
@mutexe Right now it is only printing the characters at the top of the menu, but I want it below as well. See this http://i60.tinypic.com/33onmgx.png
put lines 54 to 57 inside a function, passing in outChar as a parameter, then call it wherever you want.
@mutexe I'm sorry, but I have no idea what that is.. Can you show me how that would work in my code so I can learn for future reference? Thank you.
Last edited on
@sportstool

Here is what I think you are referring to.

EDIT:: Corrected some code. Added comments as to what I did

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 );
  }


I'll let mutexe show a function call style.
Last edited on
@whitenite1 yes, that's it. thank you.
Topic archived. No new replies allowed.