Menu system for console app, need assistance

Hello.

I am attempting to develop a win32 console menu system using VC++ 2010 under some specific parameters: It gives the user an option to choose 1 through 20, or push x to exit. I attempted to receive input from the user using a char variable and using cin >>, and processing the input with a switch statement (Case 1 thru Case 20, Case x). I discovered that if the user inputed a double digit number, 10 for example, the switch statement would process case 1 and case 0. I can't switch the input variable to an int because it won't store anything in the variable if the user selects "x". The menu system has to fit the parameters I stated above, so my question is: is there a way to setup the menu with a char variable that will process the input as '10' rather than '1' and '0'? Or to translate "x" into it's ASCII value before it's passed to the int variable? Or is using a string my only option for this setup?

Edit: Code found
Last edited on
OK, I was able to recover my lost code:
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
// main.cpp :	
#include "stdafx.h"
#include <iostream>
#include <cstdio>


void ProcessInput(char Input)
{ 
	switch (Input)
		{
			case '1':
				std::cout << "Execute one";
				break;
			case '2':
				std::cout << "Execute two";
				break;
			case '3':
				std::cout << "Execute three";
				break;
			case '4':
				std::cout << "Execute four";
				break;
			case '5':
				std::cout << "Execute five";
				break;
			case '6':
				std::cout << "Execute six";
				break;
			case '7':
				std::cout << "Execute seven";
				break;
			case '8':
				std::cout << "Execute eight";
				break;
			case '9':
				std::cout << "Execute nine";
				break;
			case '10':
				std::cout << "Execute ten";
				break;
			case '11':
				std::cout << "Execute eleven";
				break;
			case '12':
				std::cout << "Execute twelve";
				break;
			case '13':
				std::cout << "Execute thirteen";
				break;
			case '14':
				std::cout << "Execute fourteen";
				break;
			case '15':
				std::cout << "Execute fifteen";
				break;
			case '16':
				std::cout << "Execute sixteen";
				break;
			case '17':
				std::cout << "Execute seventeen";
				break;
			case '18':
				std::cout << "Execute eighteen";
				break;
			case '19':
				std::cout << "Execute nineteen";
				break;
			case '20':
				std::cout << "Execute twenty";
				break;
			default:
				std::cout << "Invalid entry.  Try again." << std::endl;
				break;
		}
}

char StartMenu()
{
	char Selection = ' ';
	std::cout << "Enter number of pallets (1-20) or \"x\" to Exit : ";
	std::cin >> Selection;
	Selection = toupper(Selection);

	return Selection;
}


int main()
{
	char MenuSelection;
	MenuSelection = StartMenu();
	while(toupper(MenuSelection) != 'X')
	{
		ProcessInput(MenuSelection);
		MenuSelection = StartMenu();
	}
	std::cout << "Exiting Program." << std::endl;
	return 0;

}


I want the user to be able to choose a number between 1-20, but if the user enters a double digit number, 14 for example, the program will execute case 1 and case 4. What can I do to get the program to process the input as case 14 instead of case 1 and 4?
Like this ?????
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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

void ProcessInput(int Input)
{
	switch (Input)
		{
			case 1:
				std::cout << "Execute one";
				break;
			case 2:
				std::cout << "Execute two";
				break;
			case 3:
				std::cout << "Execute three";
				break;
			case 4:
				std::cout << "Execute four";
				break;
			case 5:
				std::cout << "Execute five";
				break;
			case 6:
				std::cout << "Execute six";
				break;
			case 7:
				std::cout << "Execute seven";
				break;
			case 8:
				std::cout << "Execute eight";
				break;
			case 9:
				std::cout << "Execute nine";
				break;
			case 10:
				std::cout << "Execute ten";
				break;
			case 11:
				std::cout << "Execute eleven";
				break;
			case 12:
				std::cout << "Execute twelve";
				break;
			case 13:
				std::cout << "Execute thirteen";
				break;
			case 14:
				std::cout << "Execute fourteen";
				break;
			case 15:
				std::cout << "Execute fifteen";
				break;
			case 16:
				std::cout << "Execute sixteen";
				break;
			case 17:
				std::cout << "Execute seventeen";
				break;
			case 18:
				std::cout << "Execute eighteen";
				break;
			case 19:
				std::cout << "Execute nineteen";
				break;
			case 20:
				std::cout << "Execute twenty";
				break;
			default:
				std::cout << "Invalid entry.  Try again." << std::endl;
				break;
		}
		std::cout << std::endl;
}

int StartMenu()
{
	int Selection = 0;
	std::cout << "Enter number of pallets (1-20) or \"0\" to Exit : ";
	std::cin >> Selection;
	//Selection = toupper(Selection);

	return Selection;
}


int main()
{
	int MenuSelection = 0;
	MenuSelection = StartMenu();
	while(MenuSelection != 0)
	{
		ProcessInput(MenuSelection);
		MenuSelection = StartMenu();
	}
	std::cout << "Exiting Program." << std::endl;
	return 0;

}
Last edited on
It can't use 0 for exit, and it can't use int since ints can't accept alpha characters. Read the post.
Topic archived. No new replies allowed.