3. Convert the percentage system score to 5 levels of output

Source: Internet
Author: User

(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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.