Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Write a function that displays the corresponding letter grade

I’m supposed to make a user-defined function that will print the letter grade of the following mark range (ex: 99-100 = A+), but when I execute the code, it functions properly except it prints the number 1 on a new line.

Example Input:
Please input your grade in ICT:
99

Example Output:
A+
1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include <iostream>

using namespace std;

void gr(char);
void gr2(char, char);

int main() {
    int grade;
    
    cout << "Please input your grade in ICT:" << endl;
    cin >> grade;
    
    if(grade >= 99 && grade <= 100){
        gr2('A', '+');
    }
    
    else if(grade >= 95 && grade <= 98){
        gr2('A', '-');
    }
    
    else if(grade >= 90 && grade <= 94){
        gr('A');
    }
    
    else if(grade >= 85 && grade <= 89){
        gr2('B', '+');
    }
    
    else if(grade >= 81 && grade <= 84){
        gr2('B', '-');
    }
    
    else if(grade >= 75 && grade <= 80){
        gr('B');
    }
    
    else if(grade >= 71 && grade <= 74){
        gr('C');
    }
    
    else if(grade >= 61 && grade <= 70){
        gr('D');
    }
    
    else{
        gr('F');
    }
    
    cout << gr;
    
  return 0;  
    
}

void gr(char a){
    int gr;
    cout << a << endl;

}

void gr2(char a, char b){
    
    int gr2;
    cout << a << b << endl;
}

>Solution :

Just remove the line cout << gr; and the two variable definitions int gr; and int gr2;.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading