I need help creating a grade calculator in C. I am not allowed to use conditional statements. My problem is that I have written code to determine how many total points the student has, but I cannot think of a way to classify those points as an A (90-100), B (80-89), etc. without using conditional statements. My teacher gave us a hint and told us to use

and then a printf statement.

I understand somewhat where he's going, but not how to put it all togethor to acheive my goal. Any thoughts?

4
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by abhimanipal

I suppose one way to do it would be to create an array of 101 characters, each array element represents the numeric grade. The use the grade to index into that array. For example

``````char grades[101] = {0};

// now get the grade
int score = 93;
char gr = grades[score];``````

I suppose one way to do it would be to create an array of 101 characters, each array element represents the numeric grade. The use the grade to index into that array. For example

Or create an array of 11 characters

``````char grades[11] = {'J' ,'I', 'H' ,'G', 'F' ,'E','D', 'C', 'B', 'A', 'A'};

// now code to get grade
int score = 93;
char gr = grades[score/10];``````

Are you allowed to use relational operators ?

If yes you could do something of this sort

``````total_marks= 85                             //For example if the total marks are 85

{
i=total_marks;
for(;i>=90;)
{
printf("A\n");
exit(1);
}
for(;i>=80;)
{
printf("B\n");
exit(1);
}
}``````

Edited by abhimanipal: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.