Lab4B - female.!!!" <<...

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

View Full Document Right Arrow Icon
// IfTest.cpp //---------------------------- #include <iostream> using namespace std; /*------------------ Read Gender code ---> For male is 'M' or 'm'. For female is 'F' or 'f'. Read Age: Four groups --> 1-20, 21-30, 31-39, 40 and over. Print appropriate message. ---------------------*/ int main() { char gender; int age; // read gender code to get started cout << "Enter gender( 'M' or 'm' for male, 'F' or 'f' for female. ): "; cin >> gender; // Verify input: Entered character must be 'F' or 'M' or 'f' or 'm' if(!(gender == 'M' || gender == 'm' || gender == 'F' || gender == 'f')) { cout << endl<<endl; cout <<"Illegal gender. Must enter 'M' or 'm' for male, 'F' or 'f' for
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: female.!!!&quot; &lt;&lt; endl; cout &lt;&lt; endl&lt;&lt;endl; return 0; } cout &lt;&lt; &quot;Enter age: &quot;; cin &gt;&gt; age; // Verify entered age, must be between 1 and 50 if( age &lt; 1 || age &gt; 50 ) { cout &lt;&lt; endl&lt;&lt;endl; cout &lt;&lt; &quot;Illegal age&quot; &lt;&lt; endl; cout &lt;&lt; endl&lt;&lt;endl; return 0; } cout &lt;&lt; endl&lt;&lt;endl; if( gender == 'M' || gender == 'm') cout &lt;&lt; &quot;Male&quot;; else cout &lt;&lt; &quot;Female&quot;; cout &lt;&lt; &quot; and &quot; ; if( age &lt;= 20 ) cout &lt;&lt; &quot;Very Young.&quot; &lt;&lt; endl; else if( age &lt;= 30 ) cout &lt;&lt; &quot;Young.&quot; &lt;&lt; endl; else if ( age &lt;= 39) cout &lt;&lt; &quot;Experienced.&quot; &lt;&lt; endl; else cout &lt;&lt; &quot;Getting up there.&quot; &lt;&lt; endl; cout &lt;&lt; endl&lt;&lt;endl; cout &lt;&lt; &quot;==================================\n&quot;; return 0 ; }...
View Full Document

This note was uploaded on 11/01/2009 for the course CS 101 at USC.

Ask a homework question - tutors are online