// // Filename: pgm2_2b.cpp // // Description: Demonstration of Nested If's and Nested conditional if's. // // ENSC 104: Digital Computer Programming // // Instructor: Dr. Walsh // // Section: 2 // // Date Created: 01/29/98 // Last Modified: 01/29/98 // // Name: N/A // #include main() { int grade=0; cout << "Enter the student's grade: "; cin >> grade; cout << "You entered the following grade: " << grade << endl << endl; // // Example #1 // if ( grade >= 90 ) cout << "Your grade is an A!\n"; else if ( grade >= 80 ) cout << "Your grade is an B!\n"; else if ( grade >= 70 ) cout << "Your grade is an C!\n"; else if ( grade >= 60 ) cout << "Your grade is an D!\n"; else cout << "Your grade is an F!\n\n"; // // Example #2 // if ( grade >= 90 ) cout << "Your grade is an A!\n"; else if ( grade >= 80 ) cout << "Your grade is an B!\n"; else if ( grade >= 70 ) cout << "Your grade is an C!\n"; else if ( grade >= 60 ) cout << "Your grade is an D!\n"; else cout << "Your grade is an F!\n\n"; // // Example #3 // if ( grade >= 90 ) { cout << "Your grade is an A!\n"; } else if ( grade >= 80 ) { cout << "Your grade is an B!\n"; } else if ( grade >= 70 ) { cout << "Your grade is an C!\n"; } else if ( grade >= 60 ) { cout << "Your grade is an D!\n"; } else { cout << "Your grade is an F!\n\n"; } // // Example #4: Nested Conditional If's // cout << ( grade >= 90 ? "Your grade is an A!\n" : ( grade >= 80 ? "Your grade is an B!\n" : ( grade >= 70 ? "Your grade is an C!\n" : ( grade >= 60 ? "Your grade is an D!\n" : "Your grade is an F!\n") ) ) ) << endl; return 0; }