Having an issue getting this to work properly. I had it working with the switch statement within the function, but later instructions said that it must be inside of main. I just get a loop no matter what I do. 5 needs to exit the program, all the other selections need to display the corresponding cout statements. I've done something to where the inputs are not actually passing into the switch statement. If any value other than 1-5 is put in, the menu should repeat and prompt the user again. Thanks in advance.
#include <iostream>
#include <cmath>
#include <cstdlib>
usingnamespace std;
int call_menu(int selection);
double kilo_m(double miles);
int main()
{
int selection, number;
do
{
call_menu(selection);
} while (selection<1||selection>5);
number = call_menu(selection);
cout << number << endl;
switch (number)
{
case 1:
cout << "You selected the Miles to Kilometers option.\n";
cout << endl;
break;
case 2:
cout << "You selected the BMI option.\n";
cout << endl;
break;
case 3:
cout << "You selected the Distance Between Two Points option.\n";
cout << endl;
break;
case 4:
cout << "You selected the Taylor Series option.\n";
cout << endl;
break;
case 5:
return 0;
}
returntrue;
return 0;
}
int call_menu (int selection)
{
int choice, result;
cout << " 1. Miles to Kilometers\n";
cout << " 2. BMI\n";
cout << " 3. Distance Between Two Points\n";
cout << " 4. Taylor Series\n";
cout << " 5. Quit\n";
cout << endl;
cout << " Enter an operation number : ";
cin >> choice;
result = choice;
return (result);
}
int selection = 0;
int number = 0;
bool run = true;
do
{
number = call_menu(selection);
switch (number)
{
case 1:
cout << "You selected the Miles to Kilometers option.\n";
cout << endl;
break;
case 2:
cout << "You selected the BMI option.\n";
cout << endl;
break;
case 3:
cout << "You selected the Distance Between Two Points option.\n";
cout << endl;
break;
case 4:
cout << "You selected the Taylor Series option.\n";
cout << endl;
break;
case 5:
run = false;
}
} while (run == true);
and your call_menu function should look like this -
1 2 3 4 5 6 7 8 9 10 11 12
int call_menu(int selection)
{
cout << " 1. Miles to Kilometers\n";
cout << " 2. BMI\n";
cout << " 3. Distance Between Two Points\n";
cout << " 4. Taylor Series\n";
cout << " 5. Quit\n";
cout << endl;
cout << " Enter an operation number : ";
cin >> selection;
return selection;
}