Switch <variable name>
Case <Value 1>
Statement(s)
Case <Value 2>
Statement(s)
Case <Value 3>
Statement(s)
Case <Else>
Statement(s)
End Switch
Switch OldGrade
Case 'A'
NewGrade = 'D'
Case 'B'
NewGrade = 'C'
Case Else
Display "Old Grade Not Valid"
End Switch
The 'C' code for this problem is:
switch(OldGrade) { case 'A': NewGrade = 'D'; break; case 'B': NewGrade = 'C'; break; case 'C': NewGrade = 'P'; break; default: NewGrade = OldGrade; break; }
You can test multiple cases, all having the same outcome:
switch(OldGrade) { case 'A': case 'a': NewGrade = 'D'; break; case 'B': case 'b': NewGrade = 'C'; break; }
No comments:
Post a Comment