LectureNine - Lecture 7 Control Structure I (Selection) –...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture 7 Control Structure I (Selection) – Part II By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department Structure ¡ switch ¡ Useful when variable or expression is tested for multiple values. ¡ Consists of a series of case labels and an optional default case. ¡ Used instead of nested if/else statements to make the code more readable and easier to trace. switch true false . . . case a case a action(s) break case b case b action(s) break false false case z case z action(s) break true true default action(s) 2 // Counting letter grades 3 #include <iostream> 4 5 using std::cout; 6 using std::cin; 7 using std::endl; 8 9 int main() { 1 int grade, // one grade 2 aCount = 0, // number of A's 3 bCount = 0, // number of B's 4 cCount = 0, // number of C's 5 dCount = 0, // number of D's 6 fCount = 0; // number of F's 7 8 cout << "Enter the letter grades." << endl 9 << "Enter the EOF character to end input." << endl; 1 while ( ( grade = cin.get() ) != EOF ) { 2 3 switch...
View Full Document

Page1 / 9

LectureNine - Lecture 7 Control Structure I (Selection) –...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online