I have to program a menu with the abillity to go back and select different options. It was working for me until i added case 3 and im not sure why? i dont know if im missing anything or maybe im writting it wrong please help me out.
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
bool quit, back;
int measurement;
double data;
do
{
cout << "0. Quit\n";
cout << "1. Length\n";
cout << "2. Mass\n";
cout << "3. Velocity\n";
cout << "4. Force\n";
cout << "5. Pressure\n";
quit = false;
cin >> measurement;
switch(measurement)
{
case 0:
quit = true;
break;
case 1:
do
{
cout << "0. Back\n";
cout << "1. Millimeters to inches\n";
cout << "2. Inches to millimeters\n";
back = false;
cin >> measurement;
switch(measurement)
{
case 0:
back = true;
break;
case 1:
cout << "Enter a length in Millimeters\n";
cin >> data;
data /= 25.4;
cout << "It equals " << data << "in.\n";
break;
case 2:
cout << "Enter a length in Inches\n";
cin >> data;
data *= 25.4;
cout << "It equals " << data << "mm.\n";
break;
default:
break;
}
}while(back != true);
break;
case 2:
do
{
cout << "0. Back\n";
cout << "1. Kilograms to Pounds\n";
cout << "2. Pounds to Kilograms\n";
back = false;
cin >> measurement;
switch(measurement)
{
case 0:
back = true;
break;
case 1:
cout <<"Enter a mass in Kilograms\n";
cin >> data;
data *= 2.2;
cout << "It equals " << data << "lbs.\n";
break;
case 2:
cout <<"Enter a mass in Pounds\n";
cin >> data;
data /= 2.2;
cout <<"It equals " << data << "Kg\n";
break;
default:
break;
}
}while(back != true);
break;
case 3:
do
{
cout <<"0. Back\n";
cout <<"1. Kilometers per hour to Miles per hour\n";
cout <<"2. Miles per hour to Kilometers per hour\n";
back = false;
cin >> measurement;
switch(measurement)
{
case 0:
back = true;
break;
case 1:
cout << "Enter a velocity in Kilometers per hour\n";
cin >> data;
data /= 1.609;
cout <<"It equals " << data << "Mph\n";
break;
case 2:
cout << "Enter a velocity in Miles per hour\n";
cin >> data;
data *= 1.609;
cout <<"It equals " << data << "Kph\n";
break;
default:
break;
}
}while(back != true);
break;
case 4:
do
{
cout <<"0. Back\n";
cout <<"1. Newtons to Pound Force\n";
cout <<"2. Pound Force to Newtons\n";
back = false;
cin >> measurement;
switch(measurement)
{
case 0:
back = true;
break;
case 1:
cout << "Enter a Force in Newtons\n";
cin >> data;
data *= .2248;
cout <<"It equals " << data << "lbf\n";
break;
case 2:
cout << "Enter a Force in Pounds\n";
cin >> data;
data *= 4.448;
cout <<"It equals " << data << "N\n";
break;
default:
break;
}
}while(back != true);
break;
case 5:
do
{
cout <<"0. Back\n";
cout <<"1. Pascal to Pound per square inch\n";
cout <<"2. Pound per square inches to Pascal\n";
back = false;
cin >> measurement;
switch(measurement)
{
case 0:
back = true;
break;
case 1:
cout << "Enter a Pressure in Pascals\n";
cin >> data;
data *= .000145;
cout <<"It equals " << data << "Psi\n";
break;
case 2:
cout << "Enter a Pressure in Pounds per square inch\n";
cin >> data;
data *= 6894.757;
cout <<"It equals " << data << "Pa\n";
break;
default:
break;
}
}while(back != true);
break;
}
}while(quit =! true);
system("pause");
return 0;
}