help! calculate student grades

please help me write a code that allows me to calculate grades.
the question is:
program should prompt user to enter
i) total marks for each module
ii) marks obtained in each module.
calculate percentage of four modules, then program should calculate semester percentage & semester grade then display it on screen

the criteria of finding the grade should be:
1- if percentage >=70 then grade= D
2- if percentage >=60 && percentage <70 then grade=M
3- if percentage >=50 && percentage <60 then grade=P
4- if percentage >=10 && percentage <50 then grade=R
5 2- if percentage <10 then grade=F

SAMPLE OUTPUT:

Please enter total marks and marks obtained in Module 1
Total Marks: 100
Marks obtained: 70
Percentage: 70
Grade: D

Please enter total marks and marks obtained in Module 2
Total Marks: 100
Marks obtained: 60
Percentage: 60
Grade: M

Please enter total marks and marks obtained in Module 1
Total Marks: 100
Marks obtained: 55
Percentage: 55
Grade: P

Please enter total marks and marks obtained in Module 1
Total Marks: 100
Marks obtained: 40
Percentage: 40
Grade: R

Make good use of conditions, loops and functions where possible.

Please HEEEEEEEEEEEEEEEEEEEELP Me write this code.

I'm using DevCPP
Thank you in advance
Last edited on
Start it and we will help you from there.
We don't do the homework for you
i have done majority of it but for some reason whenever i run it, it runs fine, but gives me wrong result than what i was hoping to get.

regardless of what grade i have inputted i get the result as (R) as in referral. here is my code:


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

int main(int argc, char *argv[]){


int a, b, c, d, e, f, x, y;
a = 100;
y = b+c+d+e;
x = y;

cout<< "This Program will calculate Percentage and Grade of a Student in Four Modules" <<endl<<endl;

cout<< "Please input Total Marks " <<endl;
cin>> a;
cout<< "Marks obtained in Module 1: " <<endl;
cin>> b;

if (x/4 >= 10 < 50)
{cout<< "Grade = R" <<endl<<endl;
}
else if (x/4 >= 50 < 60)
{cout<< "Grade = P" <<endl<<endl;
}
else if (x/4 >= 60 < 70)
{cout<< "Grade = M" <<endl<<endl;
}
else if (x/4 >= 70)
{cout<< "Grade = D" <<endl<<endl;
}

cout<< "Please input Total Marks " <<endl;
cin>> a;
cout<< "Marks obtained in Module 2: " <<endl;
cin>> c;

if (x/4 >= 10 < 50)
{cout<< "Grade = R" <<endl<<endl;
}
else if (x/4 >= 50 < 60)
{cout<< "Grade = P" <<endl<<endl;
}
else if (x/4 >= 60 < 70)
{cout<< "Grade = M" <<endl<<endl;
}
else if (x/4 >= 70)
{cout<< "Grade = D" <<endl<<endl;
}

cout<< "Please input Total Marks " <<endl;
cin>> d;
cout<< "Marks obtained in Module 3: " <<endl;
cin>> d;

if (x/4 >= 10 < 50)
{cout<< "Grade = R" <<endl<<endl;
}
else if (x/4 >= 50 < 60)
{cout<< "Grade = P"<<endl<<endl;
}
else if (x/4 >= 60 < 70)
{cout<< "Grade = M" <<endl<<endl;
}
else if (x/4 >= 70)
{cout<< "Grade = D" <<endl<<endl;
}

cout<< "Please input Total Marks " <<endl;
cin>> e;
cout<< "Marks obtained in Module 4: " <<endl;
cin>> e;


if (x/4 >= 10 < 50)
{cout<< "Grade = R"<<endl<<endl;
}
else if (x/4 >= 50 < 60)
{cout<< "Grade = P"<<endl<<endl;
}
else if (x/4 >= 60 < 70)
{cout<< "Grade = M"<<endl<<endl;
}
else if (x/4 >= 70)
{cout<< "Grade = D"<<endl<<endl;
}


cout<<endl;


system ("PAUSE");
return EXIT_SUCCESS;
}


Thank you
Last edited on
Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

if (x/4 >= 10 < 50)

This is not how you do compound conditional statements in C++. You ought to go back to your textbook and read up on how to use the && and || operators.

Topic archived. No new replies allowed.