//* A sample program that uses a menu *

#include <iostream> using namespace std; void task_A() { // ... anything that would be useful for you // ... to do in your program when user selects // ... this particular task cout << "Task A has been performed" << endl; } void task_B(double par) { // ... anything that would be useful for you // ... to do in your program when user selects // ... this particular task cout << "Task B has been performed for parameter " << par << endl; } double task_C(double p1, int p2) { // ... anything that would be useful for you // ... to do in your program when user selects // ... this particular task double result=p1*p2; cout << "Task C has been performed for parameters " << p1 << " and " << p2 << endl; return(result); } int main() { char choice; // we need to declare the choice outside of this do-while loop // because we need to check it in the exit condition do { // print or repeat the main menu, ask for the selection cout << "\n\nMAIN MENU:\n\n" << "a - do task A\n" << "b - do task B\n" << "c - do task C\n" << "X - eXit the program\n" << "\n--> "; cin >> choice; // you cannot declare variables directly in switch-case // so we declare them before it. There are ways around though double x, y, r; int z; switch (choice) { case 'a' : case 'A' : task_A(); break; case 'b' : case 'B' : cout << "Please enter a number " << endl; cin >> x; task_B(x); break; case 'c' : case 'C' : cout << "Please enter two numbers " << endl; cin >> y >> z; r=task_C(y, z); cout << "The answer is " << r << endl; break; case 'X' : // do nothing here, we will exit the main loop soon break; default : cout << "\aI am sorry, but I did not recognize your selection\n" << "Could you please choose one from the following options:\n\n" << endl; } } while (choice!='X'); cout << "Thank you for using this software.\n" << "I hope to see you again soon." << endl; return(0); }