Student Grading Program Help

This is a simple program designed to output the grade a student earned by inputting score. My only problem is "Molly (case sensitive) is the teacher's special favorite, so if she earns less than an A, her grade is promoted to the next higher grade". I can't figure out how to make that possible with an if statement or switch statement. So for example, if Molly's score were to be 40 her grade outputted would be a D. Here is my code

#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

bool die(const string & msg);

int main(){
string name;
string Molly;
int score;
cout << "Enter first name: ";
cin >> name;
cout << "Enter score: ";
cin >> score || die("input failure");
if (score < 0 || score > 100) die("Score must be in the range [0,100] ");
if ( name == Molly && score < 60)
cout << "D" << endl;
else
if (score >= 90)
cout << "A" << endl;
else
if (score >= 80)
cout << "B" << endl;
else
if (score >= 70)
cout << "C" << endl;
else
if (score >= 60)
cout << "D" << endl;
else
cout << "F" << endl;

}

bool die(const string & msg){
cout << "Fatal error: " << msg << endl;
exit(EXIT_FAILURE);
}
Last edited on
closed account (48T7M4Gy)
string Molly = "Molly";

1
2
3
if name = molly and her score < 60
          then output "D"
          otherwise add 10 to her grade and proceed as with other students

Last edited on
(1) If you don't care about the actual score, but want it to just increase the letter grade then:

if (score<90)
{ score+=10 }

(2) If you care about the actual numerical score, then:
(A) Check if it is less than 90
(B) Check if it is less than 60 (If it is, then set it to 60. If not, move on to C)
(C) Check/convert to an int or round it
(D) The number now must be between 60 and 89. Now, convert to a string.
(E) Check the 1st character and set it accordingly. So, if:
if (score[0]=='6')
{ int n=70; }
if (score[0]=='7')
{ int n=80; }
if (score[0]=='8')
{ int n=90; }
Last edited on
@kemort I tried that and it works to an extent as in my program outputs both "Molly gets a D" and "Molly gets an F". What should i alter so the second statement does not appear.
Never mind I found my error that caused the second statement to appear. Thank you guys so much!
closed account (48T7M4Gy)
As a quick thought without checking you have to change Molly's score before performing the 'swindle' because even though the grade will change the score will still produce the old grade.
Topic archived. No new replies allowed.