Menus

How do I make basic menus in C++? Not the "[S]tart [Q]uit" stuff. I mean like a line of text that is always at the top that tells the time and move number. It has to always stay at the top of the screen. Any idea how to do this?
I use Dev-C++.
Last edited on
In a terminal? NCurses is the library used for Vim, etc..
@DOSmaster

Here is a small Menu program, to get you started. After you understand how it works, you should be able to adapt it to your program.

If you run into problems, post your code,( using the <> symbol on right side of this input box)
and someone will help 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Menu.cpp : main project file.
#include <iostream>
#include <conio.h>
#include <string>
#include <windows.h>

using namespace std;

#define ENTER 13
#define UP 72
#define DOWN 80

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;

void gotoXY(int,int);

int main(void)
{
	int menu_item=0, ch, x=7;
	gotoXY(18,5);
	cout << "Main Menu";
	gotoXY(18,7);
	cout << "->";
	do
	{
		// Add inside do/while loop, the clock function. Use the gotoXY() function to place the time where
                //  you want it.
                gotoXY(20,7);
		cout << "Addition";
		gotoXY(20,8);
		cout << "Multiplication";
		gotoXY(20,9);
		cout << "Division";
		gotoXY(20,10);
		cout << "Subtraction";
		gotoXY(20,11);
		cout << "Quit Program";

		ch = _getch();
		switch(ch)
		{
		case UP:
			if(menu_item-1>=0)
			{
				gotoXY(18,x);
				cout << "  ";
				x--;
				gotoXY(18,x);
				cout << "->";
				menu_item--;
				break;
			}

		case DOWN:
			if(menu_item+1<=4)
			{
				gotoXY(18,x);
				cout << "  ";
				x++;
				gotoXY(18,x);
				cout << "->";
				menu_item++;
				break;
			}
		case ENTER:
			{
				if(menu_item==0)
				{
					gotoXY(20,16);
					cout << "You chose Addition...     ";
					break;
				}
				if(menu_item==1)
				{
					gotoXY(20,16);
					cout << "You chose Multiplication...";
					break;
				}
				if(menu_item==2)
				{
					gotoXY(20,16);
					cout << "You chose Division...      ";
					break;
				}
				if(menu_item==3)
				{
					gotoXY(20,16);
					cout << "You chose Subtraction...   ";
					break;
				}
				if(menu_item==4)
				{
					gotoXY(20,19);
					cout << "The program has now terminated!!";
					ch = 4;
					break;
				}
			}
		}
	}while(ch != 4);
	
	gotoXY(20,21);
	return 0;
}

void gotoXY(int x, int y) 
{ 
	CursorPosition.X = x; 
	CursorPosition.Y = y; 
	SetConsoleCursorPosition(console,CursorPosition); 
}
Topic archived. No new replies allowed.