|
Switch Statement - Assign Pressure Values
% cat press_switch.cpp
// assign pressure values using the switch statement
#include <iostream>
using namespace std;
int main()
{
double pressure;
int setting;
cout << "Enter the setting to assign the pressure:
";
cin >> setting;
switch( setting )
{
case 1: pressure = 25.0;
break;
case 2: pressure = 35.0;
break;
case 3: pressure = 45.0;
break;
case 4:
case 5:
case 6: pressure = 49.0;
break;
default: pressure = -999.0;
cout << "setting must be 1 - 6" << endl;
}
cout << "For setting " << setting <<
" the pressure is " << pressure
<< endl;
return 0;
}
% g++ press_switch.cpp
% a.out
Enter the setting to assign the pressure: 1
For setting 1 the pressure is 25
% a.out
Enter the setting to assign the pressure: 3
For setting 3 the pressure is 45
% a.out
Enter the setting to assign the pressure: 4
For setting 4 the pressure is 49
% a.out
Enter the setting to assign the pressure: 9
setting must be 1 - 6
For setting 9 the pressure is -999
|