Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 
 

What's inside.

Ta Email

Download Compiler

Final Project

Lab Notes

Office Hours

Schedule

Syllabus

Announcements

Check Grades

 

CSci 1113 Home

 
 

Printer-friendly version

 
Assign Pressure Values Using  a Multiway if-else Statement

% cat press_if.cpp
// assign pressure values using a multiway if-else statement
#include <iostream>
using namespace std;

int main()
{
   double pressure;
   int setting;

   cout << "Enter the setting to assign the pressure: ";
   cin >> setting;

   // multiway if-else statement

   if( setting == 1 )
     pressure = 25.0;
   
   else if( setting == 2 )
     pressure = 35.0;

   else if( setting == 3 )
     pressure = 45.0;

   else if ( setting == 4 || setting == 5 || setting == 6 )
     pressure = 49.0;

   else
   {
     cout << "setting must be 1-6\n";
     pressure = -999.0;
   }

   cout << "For setting " << setting << " the pressure is " << pressure << endl;

   return 0;

}
% g++ press_if.cpp
% 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: 6
For setting 6 the pressure is 49
% a.out
Enter the setting to assign the pressure: 8
setting must be 1-6
For setting 8 the pressure is -999
 
The University of Minnesota is an equal opportunity educator and employer.
CSci 1113: C++ Programming