Programming in C++ parameter void Display Message( int index if index 35) cout<<“ Pleasant; else if index <= 60) cout<<“ Unpleasant”; else cout<<“ Health hazard”,; 16
16 parameter void DisplayMessage( int index ) { if ( index < 35 ) cout << “Pleasant”; else if ( index <= 60 ) cout << “Unpleasant”; else cout << “Health Hazard”; }
Programming in C++ The Rest of the Program include <iostream> void Display Message(int); ∥ prototype using namespace std; int main( argument int pollutionIndex; cout <<"Enter air pollution/dex" cin > pollutionIndex Display Message( pollutionIndex);∥ca∥ return o 17
17 #include <iostream> void DisplayMessage (int); // prototype using namespace std; int main ( ) argument { int pollutionIndex; cout << “Enter air pollution index”; cin >> pollutionIndex; DisplayMessage(pollutionIndex); // call return 0; } The Rest of the Program
Programming in C++ The Return Statement )The main function uses the statement return 0. to return the value 0(or 1 or some other value) to its caller, the operating system )Every value-returning function must return its function value this way 18
18 The Return Statement ➢The main function uses the statement return 0; to return the value 0 (or 1 or some other value) to its caller, the operating system. ➢Every value-returning function must return its function value this way
Programming in C++ The Return Statement(Cont A second form of the Return Statement. return. &s is valid only in the body block of void functions s causes control to leave the function and immediately return to the calling block leaving any subsequent statements in the function body unexecuted 19
19 The Return Statement (Cont.) A second form of the Return Statement: return; ❖is valid only in the body block of void functions ❖causes control to leave the function and immediately return to the calling block leaving any subsequent statements in the function body unexecuted