Answer to Question #252521 in C++ for Urooj

Question #252521

Using a switch statement write a program that evaluates a student's mark (0-100) to the respective grade. Grade boundaries are defined below

Less than 40: F

Between 40 and 49: E

Between 50 and 59: D

Between 60 and 69: C

Between 70 and 79: B

Greater or equal to 80: A                                           Your program should ask the user to input the student's full name and mark (between 0 - 100) and then output the student's name and grade (A - F). You should also handle invalid grade values


1
Expert's answer
2021-10-17T09:29:37-0400
#include <iostream>
using namespace std;
int main(){
    char name[50];
    int mark;
    cout<<"Enter full name: ";
    cin.getline(name, 50);
    cout<<"Enter mark (between 0 - 100): ";
    cin>>mark;
    if(mark > 100 || mark < 0) mark = -10;
    switch(mark / 10){
        case 10:;
        case 9:;
        case 8:cout<<"Name: "<<name<<"\nGrade A\n"; break;
        case 7:cout<<"Name: "<<name<<"\nGrade B\n"; break;
        case 6:cout<<"Name: "<<name<<"\nGrade C\n"; break;
        case 5:cout<<"Name: "<<name<<"\nGrade D\n"; break;
        case 4:cout<<"Name: "<<name<<"\nGrade E\n"; break;
        case 3:;
        case 2:;
        case 1:;
        case 0:cout<<"Name: "<<name<<"\nGrade F\n"; break;
        default: cout<<"Invalid marks\n";
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS