Click here to Skip to main content
15,888,088 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Create a program that will ask the user for his/her final grade and it display the equivalent grade (refer to below table) and its remarks.
Grade
Equivalent
Remarks
from
to
no.
letter

0.0
59.4
0.00
F
???
59.5
64.4
1.00
D
???
64.5
70.4
1.50
D+
???
70.5
76.4
2.00
C
???
76.5
82.4
2.50
C+
???
82.5
88.4
3.00
B
???
88.5
94.4
3.50
B+
???
94.5
100.0
4
A
???

What I have tried:

#include<stdio.h>
main() {

/* This program will ask the user for their final grade and it will display the equivalent grade(refer to the below table) & its remarks
note:- you are the one to create your own remarks. the remarks should inspire them
Grades
from 0.0 to 59.4 is number (0.0) which F in letter
from 59.5 to 64.4 is number (1.00) which is D
from 64.5 to 70.4 is number (1.50) which is D+
from 70.5 to 76.4 is number (2.00) which is C
from 76.5 to 82.4 is number (2.50) which is C+
from 82.5 to 88.4 is number (3.00) which is B
from 88.5 to 94.4 is number (3.50) which is B+
from 94.5 to 100.0 is number (4) which is A
sample output
enter your fina grade : 55
equivalent grade is 0.0 or F
remark= "Have a nice vacation"
*/
int grade,equi_grade_num,remarks;
grade=0 to 100.0
char a, b, c, d, f, p, l, u;
a='A';
b='B';
c='C';
d='D';
f='F';
p='B+';
l='C+';
u='D+';

printf("Input your final grade: ");
scanf("%d",&grade);

printf("Your equivalent grade is %d: or %c: ");
scanf("%d" "%c",&equi_grade_num,&a,&b,&c,&d,&f,&p,&l,&u);

if (grade==0 || grade<=59.4) {
scanf("%d" "%c",&equi_grade_num,&a,&b,&c,&d,&f,&p,&l,&u);
printf("Failed,needs immediate improve");
}



getch();
}
Posted
Updated 11-Mar-17 23:42pm

1 solution

That isn't going to work - as you have probably noticed!
A char variable can only hold a single "letter", so things like this:
p='B+';
l='C+';
u='D+';
Will not compile.
Go back a stage, and think again: do this in stages.
Start by getting a grade from the user, and storing it in an appropriate variable - and int variables only hold integer values, so they don't work with "59.4", or "88.5". You will have to use a different data type for your grade.

When you have that working (and by that I mean compile it, run it and make sure that when the user enters a value you can read it as a number and print it back out correctly, rejecting any "bad" inputs like "hello") look at working out which "group" the grade falls into. That's not complex, it's just a set of if...else if...else if...else statements:
C++
if (grade >= lowestGradeInFirstGroup && grade <= highestGradeInFirstGroup)
   {
   ... In first group
   }
else if (grade >= lowestGradeInSecondGroup && grade <= highestGradeInSecondGroup)
   {
   ... in second group
   }
...
else
   {
   ... in last group
   }
When you have that working (compiling and running ok) look at printing the appropriate grade code and message.

Do it in stages, and it'll be pretty easy!
But ... this is your homework, so the code is all up to you!
 
Share this answer
 
Comments
Member 13053749 12-Mar-17 6:25am    
but how do i display an equivalent grade to the grade input
OriginalGriff 12-Mar-17 6:37am    
printf?
Member 13053749 12-Mar-17 7:01am    
like how about this :- float grade, equivalent_grade_num;
char letter;
int p,l,u;
p=(B+);
l=C+;
u=D+;
letter={'A','B','C','D','F'};

printf("Enter your final grade: ");
scanf("%f",&grade);

equivalent_grade_num=0.0
if (grade==0.0 || grade<=59.4)
printf("Your equivalent grade is %f or %c%d",eqivalent_grade_num,letter,p,l,u);
OriginalGriff 12-Mar-17 7:10am    
Better, but... it won't compile!
Why do you need "equivalent_grade_num" at all? Why have p, l, u? Why "letter"?

Have you considered using a fixed string in each if block?
Member 13053749 12-Mar-17 9:22am    
how about this

float G;

printf("\nEnter your final grade: ");
scanf("%f",&G);

if (G>=0.0 && G<=59.4){
printf("\nYour equivalent grade is 0.0/F!!");
printf("\n\nYou failed!!, this is really very poor performance");
}
else if(G>=59.5 && G<=64.4){
printf("\nYour equivalent grade is 1.00/D!!");
printf("\n\nYou were just decimal points away to fail, you must apply extensive persistence!!!!!");
}
else if (G>=64.5 && G<=70.4){
printf("\nYour equivalent grade is 1.50/D+!!");
printf("\n\nYou ");
}
else if(G>=70.5 && G<=76.4){
printf("\nYour equivalent grade is 2.00/C!!");
printf("\n\nYou");
}
else if(G>=76.5 && G<=82.4){
printf("\nYour equivalent grade is 2.50/C+!!");
printf("\n\nYou ");
}
else if(G>=82.5 && G<=88.4){
printf("\nYour equivalent grade is 3.00/B!!");
printf("\n\nYou ");
}
else if(G>=88.5 && G<=94.4){
printf("\nYour equivalent grade is 3.50/B+!!");
printf("\n\nYou ");
}
else if(G>=94.5 && G<=100.0) {
printf("\nYour equivalent grade is 4/A!!");
printf("\n\nYou passed succesfully, congratz to your exceptional achievement!!");
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900