Answer:
We can use if-else statements to implement the given problem.
C++ Code:
#include <iostream>
using namespace std;
int main()
{
int marks;
cout<<"Enter the marks"<<endl;
cin>>marks;
if (marks>=90 && marks<=100)
{
cout<<"Grade: A"<<endl;
}
else if (marks>=80 && marks<=89)
{
cout<<"Grade: B"<<endl;
}
else if (marks>=70 && marks<=79)
{
cout<<"Grade: C"<<endl;
}
else if (marks>=60 && marks<=69)
{
cout<<"Grade: D"<<endl;
}
else if (marks>=0 && marks<=59 )
{
cout<<"Grade: F"<<endl;
}
else
{
cout<<"Invalid marks!"<<endl;
}
return 0;
}
Test results:
Enter the marks
100
Grade: A
Enter the marks
90
Grade: A
Enter the marks
89
Grade: B
Enter the marks
80
Grade: B
Enter the marks
79
Grade: C
Enter the marks
70
Grade: C
Enter the marks
69
Grade: D
Enter the marks
60
Grade: D
Enter the marks
59
Grade: F
Enter the marks
45
Grade: F
Enter the marks
105
Invalid marks!
Enter the marks
-6
Invalid marks!
Hence all the cases are working fine!