Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,177 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,997 people online right now. Registration is fast and FREE... Join Now!




convert number grade to letter grade function

 
Reply to this topicStart new topic

convert number grade to letter grade function, i can do it using if statements, not sure how using a function

wartech
2 Aug, 2007 - 06:29 PM
Post #1

D.I.C Head
Group Icon

Joined: 16 Oct, 2006
Posts: 106



Thanked: 3 times
My Contributions
Hey Everyone,
I need to convert the number grade to a letter grade using a function not if statements as I have done. I am a little confused about doing this. The furthest I have gotten is declaring it. Below that is my code using a for loop and if statements to convert the number grade to a letter, but I need a function to do this. Thanks for your time!

CODE

//FUNCTIONS
int num_letter(int x);  //Is this the correct declaration?


//OUTPUT
    for (i=1; i < count; i++)
    {
        grades[count] += i;
        if (grades[i] >= 91)
        {
        lgrade[i] = 'A';
        passing += 1;
        }
        else
            if (grades[i] >= 81)
        {
        lgrade[i] = 'B';
        passing += 1;
        }
            
        else
            if (grades[i] >= 71)
        {
        lgrade[i] = 'C';
        passing +=1;
        }
        else
            if (grades[i] >= 61)
        {
        lgrade[i] = 'D';
        passing +=1;
        }
        else
            if (grades[i] <= 60)
        {
        lgrade[i] = 'F';
        failing +=1;
        }

    }


User is online!Profile CardPM
+Quote Post

k.sangeeth
RE: Convert Number Grade To Letter Grade Function
2 Aug, 2007 - 08:33 PM
Post #2

D.I.C Head
**

Joined: 27 Jul, 2007
Posts: 61


My Contributions
you can write a function to take numbers and return grades.

CODE

char func(int num)
{
   if(num >= 91)
     return 'a';
   else if(num >= 81)
     return 'b'
-----------------------and so on

}


hope this helps

This post has been edited by k.sangeeth: 2 Aug, 2007 - 08:34 PM
User is offlineProfile CardPM
+Quote Post

barnwillyb
RE: Convert Number Grade To Letter Grade Function
4 Aug, 2007 - 12:29 PM
Post #3

D.I.C Head
**

Joined: 22 May, 2007
Posts: 55


My Contributions
QUOTE(wartech @ 2 Aug, 2007 - 07:29 PM) *

Hey Everyone,
I need to convert the number grade to a letter grade using a function not if statements as I have done. I am a little confused about doing this. The furthest I have gotten is declaring it. Below that is my code using a for loop and if statements to convert the number grade to a letter, but I need a function to do this. Thanks for your time!

CODE

//FUNCTIONS
int num_letter(int x);  //Is this the correct declaration?


//OUTPUT
    for (i=1; i < count; i++)
    {
        grades[count] += i;
        if (grades[i] >= 91)
        {
        lgrade[i] = 'A';
        passing += 1;
        }
        else
            if (grades[i] >= 81)
        {
        lgrade[i] = 'B';
        passing += 1;
        }
            
        else
            if (grades[i] >= 71)
        {
        lgrade[i] = 'C';
        passing +=1;
        }
        else
            if (grades[i] >= 61)
        {
        lgrade[i] = 'D';
        passing +=1;
        }
        else
            if (grades[i] <= 60)
        {
        lgrade[i] = 'F';
        failing +=1;
        }

    }




First off you would have to test for a higher score and a lower score: if (student_score < 90 && student_score > 79), then return this grade. Of course the first test would only have scores above or equal to 90: if (student_score >= 90), then return this grade, and the last test would be only scores below or equal to 62: if (student_score <= 62), then return this grade.

Now to write a function that would return the grade from the student's score. Here is a prototype: char display_student_grades( int student_score ); Now see if you can finsh it. Remember that this function has a return type of char( in this case a letter grade like 'A' ), so in each test of the actual student's score, this function has to return a value of char that matches with the int student_score.

Hope that helps!

barnwillyb

User is online!Profile CardPM
+Quote Post

wartech
RE: Convert Number Grade To Letter Grade Function
5 Aug, 2007 - 12:55 PM
Post #4

D.I.C Head
Group Icon

Joined: 16 Oct, 2006
Posts: 106



Thanked: 3 times
My Contributions
Thank you both. That really helped!!!


User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 12:56AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month