I just want modify the program below to print + or - minus after the letter grade based on the last digit.

// Chapter 6 - Exercise 1
//             A professor generates letter grades using
/*             0 -  60 F
              67 -  70 D
              71 -  80 C
              81 -  90 B
              91 - 100 A
*/
#include <iostream>

int main()
{
    std::cout << "Enter the grade #: ";
    int grade;
    std::cin >> grade;
    char letter_grade;

    if (grade <= 60)
    {
        letter_grade = 'F';
    }

    if ((grade >=61) && (grade <= 70))
    {
        letter_grade = 'D';
    }

    if ( (grade >= 71) && (grade <= 80))
    {
        letter_grade = 'C';
    }

    if ( (grade >= 81) && (grade <= 90))
    {
        letter_grade = 'B';
    }

    if ( grade >= 91)
    {
        letter_grade = 'A';
    }

    std::cout << "The letter grade is " << letter_grade << "\n";

    std::cin.get();
    return 0;
}

Recommended Answers

All 4 Replies

I just want modify the program below to print + or - minus after the letter grade based on the last digit.

// Chapter 6 - Exercise 1
//             A professor generates letter grades using
/*             0 -  60 F
              67 -  70 D
              71 -  80 C
              81 -  90 B
              91 - 100 A
*/
#include <iostream>

int main()
{
    std::cout << "Enter the grade #: ";
    int grade;
    std::cin >> grade;
    char letter_grade;

    if (grade <= 60)
    {
        letter_grade = 'F';
    }

    if ((grade >=61) && (grade <= 70))
    {
        letter_grade = 'D';
    }

    if ( (grade >= 71) && (grade <= 80))
    {
        letter_grade = 'C';
    }

    if ( (grade >= 81) && (grade <= 90))
    {
        letter_grade = 'B';
    }

    if ( grade >= 91)
    {
        letter_grade = 'A';
    }

    std::cout << "The letter grade is " << letter_grade << "\n";

    std::cin.get();
    return 0;
}

You want to add + or - depending on the last digit of the grade? I didn't quite catch your purpose...

Yes, and i'll try to make my writing more clear.(note to self read over before posting :D)

That would be very difficult seeing as you have varied boundaries between grades. An easy way round it would be laying out percentage boundaries for each grade. Ie:

A* = 90%
A+ = 88%
A  = 86%
A- = 83%
B+ = 80%
etc.

Then calculate a percentage and work out which grade they got. This would take rounding because you most likely will end up with dividing to make a decimal, though you would have a lot of if statements. There's probably an easier way to do it that I haven't thought of...

Is this thread solved? If so, please mark as. Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.