I am trying to write a menu program that will be broken down into a series of calls to function for each of the menu items. Two of the menu items will be simple programs which I wrote.
I want two of the functions to run one of the two programs I am trying to include as items in the menu.
So far I am only familiar with variables, loops, if statements, and I just learned how to write functions.
The problem I am have is that I don't quite understand how to write a function that will run one of the two programs. Also I am having a hard time writing the program in away that would allow the user to select the menu items.
Could some please help me figure this out.
Code:#include <iostream> using namespace std; int beer_on_the_wall() {int i=100; while( i <100 && i >=0) { cout << "Bottles of beer on the wall."; i--; } } int calculate() { int arg1; int arg2; cout <<"input argument one"; cin >> arg1; cout <<"input argument two"; cin >> arg2; cout << arg1 << "*" << arg2 << "=" << arg1*arg2 << endl; cout << arg1 << "+" << arg2 << "=" << arg1+arg2 << endl; cout << arg1 << "-" << arg2 << "=" << arg1-arg2 << endl; } void Exit() {} int main () { int input; cout << "1. Play beer\n"; cout << "2. load calculator\n"; cout << "3. Exit\n"; cout << "Selection: "; cin >> input; switch ( input ) { case 1: // Note the colon after each case, not a semicolon beer_on_the_wall(); break; case 2: calculate(); break; case 3: Exit(); cout <<"Good Bye\n"; break; default: // Note the colon for default, not a semicolon cout << "Error, bad input, quitting\n"; break; }
Code:Code:simplemenu.cpp