menu driven program

I need a menu driven program that has the following 5 choices.
Output a sum of even numbers
Output a table of odd numbers
Output their square root
Output all lower case and upper case letter
Quit.

I have the code to all the functions now I just need to put it into a menu driven. Which I have tried using a switch statement but have fail every time.


#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int firstNum, secondNum;
int sumEvenNum = 0;
int sumSquareOddNum = 0;

char chCounter;


int counter;

//Part a
cout << "Enter two numbers." << endl;
cout << "First number must be less than ";
cout << "the second number you enter" << endl;
cout << "Enter numbers: " << flush;
cin >> firstNum >> secondNum;
cout << endl;

//Part b
if (firstNum % 2 == 0)
counter = firstNum;
else
counter = firstNum + 1;

while (counter <= secondNum)
{
sumEvenNum = sumEvenNum + counter;
counter = counter + 2;
}

cout << "Sum of even integers between " << firstNum << " and "
<< secondNum << " = " << sumEvenNum << endl;

//Part c
if (firstNum % 2 == 0)
counter = firstNum + 1;
else
counter = firstNum;

cout << "Odd integers between " << firstNum << " and "
<< secondNum << " are: " << endl;

for (; counter <= secondNum; counter += 2)
{
cout << counter << " ";
}

cout << endl;


//Part d
cout << "Number Square of Number" << endl;
counter = 1;
while (counter <= 10)
{
cout << setw(4) << counter << setw(18)
<< counter * counter << endl;
counter++;
}

cout << endl;

//Part e
if (firstNum % 2 == 0)
counter = firstNum + 1;
else
counter = firstNum;

while (counter <= secondNum)
{
sumSquareOddNum = sumSquareOddNum + counter * counter;
counter = counter + 2;
}


//Part f
cout << "Upper case letters are: ";

chCounter = 'A';
do {
cout << chCounter << " ";
chCounter++;
} while (chCounter - 1 <= 'Z');
cout << endl;

cout << "Lower case letters are: ";
chCounter = 'a';
do {
cout << chCounter << " ";
chCounter++;
} while (chCounter - 1 <= 'z');
cout << endl;


return 0;
}


that is the code for all the different functions.
@nyaeggy

Here is the program that's menu driven. You should have inputs for options 2 and 3, also. Do not depend on a user entering option 1 after starting the program. Also use code tags. The symbol is <> under Format: to the right.
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
113
114
115
// Menu Driven.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	int firstNum, secondNum;
	int sumEvenNum = 0;
	int sumSquareOddNum = 0;
	char chCounter;
	int counter, choice;
	do
	{
		cout << "1) Output a sum of even numbers" << endl;
		cout << "2) Output a table of odd numbers" << endl;
		cout << "3) Output their square root" << endl;
		cout << "4) Output all lower case and upper case letters" << endl << endl;
		cout << "5) Quit program" << endl;
		cin >> choice;
		switch(choice)
		{
		case 1:
			cout << "Enter two numbers." << endl;
			cout << "First number must be less than ";
			cout << "the second number you enter" << endl;
			cout << "Enter numbers: " << flush;
			cin >> firstNum >> secondNum;
			cout << endl;

			if (firstNum % 2 == 0)
				counter = firstNum;
			else
				counter = firstNum + 1;	

			while (counter <= secondNum)
			{
				sumEvenNum = sumEvenNum + counter;
				counter = counter + 2;
			}
			cout << "Sum of even integers between " << firstNum << " and "
				<< secondNum << " = " << sumEvenNum << endl;
			break;

		case 2:
			if (firstNum % 2 == 0)
				counter = firstNum + 1; // firstNum and secondNum have no given values if choice 1 not used first
			else
				counter = firstNum;
			cout << "Odd integers between " << firstNum << " and "
				<< secondNum << " are: " << endl;

			for (; counter <= secondNum; counter += 2)
			{
				cout << counter << " ";
			}

			cout << endl;
			break;

		case 3:
			cout << "Number Square of Number" << endl;
			counter = 1;
			while (counter <= 10)
			{
				cout << setw(4) << counter << setw(18)
					<< counter * counter << endl;
				counter++;
			}
			cout << endl;

			if (firstNum % 2 == 0) // firstNum and secondNum have no given values if choice 1 not used first
				counter = firstNum + 1;
			else
				counter = firstNum;

			while (counter <= secondNum)
			{
				sumSquareOddNum = sumSquareOddNum + counter * counter;
				counter = counter + 2;
			}
			break;

		case 4:
			cout << "Upper case letters are: ";

			chCounter = 'A';
			do {
				cout << chCounter << " ";
				chCounter++;
			} while (chCounter - 1 <= 'Z');
			cout << endl;

			cout << "Lower case letters are: ";
			chCounter = 'a';
			do {
				cout << chCounter << " ";
				chCounter++;
			} while (chCounter - 1 <= 'z');
			cout << endl;
			break;

		case 5:
			cout << "Thanks. See you again, later.." << endl << endl;
			return 0;
		default:
			cout << "Options are only choices 1 to 5..  Thank you." << endl;
		} 
	}while (choice >=1 || choice <=5);
 return 0;
}

This code didnt compile and gave the error
>c:\users\public\documents\c++\homework7\homework7\the increadible looping machine.cpp(9): fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
1>
Sorry, nyaeggy.

The include stdafx.h, is used with Visual C++ 2008 Express Edition. Just delete it from the includes, and it should compile and run fine.
Topic archived. No new replies allowed.