I need a menu driven program for this code?

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

#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.

Update:

Yes I need to give them a menu where they need to choose what they want to do. I have tried doing in it with a switch statement several times but i apparently fail at calling the functions so i went back to just having the functions to do everything.

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 EBIN.TIPS - All rights reserved.