(1) Use if statement nesting: # include <iostream>
Using namespace STD;
Int main ()
{
Int;
Cout <"Please input your score:" <Endl;
Cin>;
If (A> 100 | A <0)
Cout <"wrong input! Please try again! "<Endl;
Else if (a> = 90 & A <= 100)
Cout <"you get an! You are doing great job! "<Endl;
Else if (a> = 80 & A <90)
Cout <"you get a B! Keep going! "<Endl;
Else if (a> = 70 & A <80)
Cout <"you get a C! It's OK, you can do better! "<Endl;
Else if (a> = 60 & A <70)
Cout <"you get an E! You pass the exam. "<Endl;
Else if (a <60)
Cout <"you did 'not pass the exam, but don't lose heart." <Endl;
Return 0;
}
(2) switch statement: # include <iostream>
Using namespace STD;
Int main ()
{
Int score, temp; // first defined, and then used
Char grade; // note that the level must be defined as level.
Cout <"Please input your score:" <Endl;
Cin> score;
Temp = (INT) score/10; // force type conversion
Switch (temp) // enter the previous data
{
Case 10: grade = 'a + '; break;
Case 9: grade = 'a'; break;
Case 8: grade = 'B'; break;
Case 7: grade = 'C'; break;
Case 6: grade = 'D'; break;
Default: grade = 'E'; break; // Other Default results are output. You cannot forget the colon.
}
Cout <"you grade is:" <Grade <Endl;
Return 0;
}