If_Age_A

If_Age_A - else if ( age < 20 ) // If the age is...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// example to demonstrate use of a multi-alternative if statement / #include <iostream> # using namespace std; u int main() { int age; cout << "Enter your age: " ; cin>> age; if ( age <= 0 ) // Verify age is positive cout <<"I guess you are not born yet.\n"; else if (age > 150) // Verify age is not too big cout <<"I cant believe you are that old!!!!!!!!.\n"; else if ( age == 100 ) // Check for century mark cout << "WOW, Congradulations, You are a century old."<<endl;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: else if ( age &lt; 20 ) // If the age is less than 20 cout &lt;&lt;&quot; You are pretty young!\n&quot;; // Just to show you it works. .. else if ( age &lt; 50) cout &lt;&lt;&quot;You still have a few good years left in you.&quot; &lt;&lt; endl ; else if (age &lt; 62) cout &lt;&lt;&quot;Enjoy your retirement, you have earned it.&quot; &lt;&lt; endl ; else if ( age &gt; 100 ) // I use else just to show an example cout&lt;&lt;&quot;You are really old\n&quot;; // Executed if no other statement is return 0 ; }...
View Full Document

Ask a homework question - tutors are online