I want to assign grades based on the test scores.
- A for 90-100.
- B for 80-90.
- C for 70-79.
- D for 60-69.
- F for 0-59.
I know if you use switch
or if..else
statements, there will be no more than 5 statements but anyone has any better solution?
I used ASCII values to go about it but in terms of lines of code it's merely the same.
Here is the code:
Score/=10;
Score=min(9,Score);
Score=9-Score;
Score+=65;
if(Score<=68)
{
cout<<static_cast<char>(Score)<<endl;
}
else
{
cout<<"F"<<endl;
}
Aucun commentaire:
Enregistrer un commentaire