Course Grading System Using Letter Grades in C++

In this C++ exercise, you will create a simple program that simulates a letter-based grading system for a course. The program will take a student's numeric grade as input and convert it into a corresponding letter grade based on standard academic thresholds.

This is a practical task to practice conditional statements, input/output operations, and logical thinking. By assigning letter grades based on ranges, students can better understand how control flow works in C++, especially using if-else if-else constructs.

You will define ranges such as:
- A for grades 90 and above
- B for grades 80 to 89
- C for grades 70 to 79
- D for grades 60 to 69
- F for grades below 60

The final output will be the letter grade assigned to the student based on their numeric input.

Group

Advanced Conditional Structures in C++

Objective

1. Prompt the user to enter a numeric grade between 0 and 100.
2. Determine the letter grade using if-else statements based on the numeric value.
3. Display the corresponding letter grade to the user.
4. Ensure proper input validation is in place.

Write a program that simulates a course grading system using letter grades.

Example C++ Exercise

 Copy C++ Code
#include <iostream>  // Include the input/output stream library

using namespace std;

int main() {
    int grade; // Variable to store the student's numeric grade

    // Prompt the user to enter their grade
    cout << "Enter your numeric grade (0-100): ";
    cin >> grade;

    // Check if the input is within a valid range
    if (grade < 0 || grade > 100) {
        cout << "Invalid grade. Please enter a number between 0 and 100." << endl;
    } else {
        // Determine the letter grade based on numeric grade
        if (grade >= 90) {
            cout << "Your letter grade is: A" << endl;
        } else if (grade >= 80) {
            cout << "Your letter grade is: B" << endl;
        } else if (grade >= 70) {
            cout << "Your letter grade is: C" << endl;
        } else if (grade >= 60) {
            cout << "Your letter grade is: D" << endl;
        } else {
            cout << "Your letter grade is: F" << endl;
        }
    }

    return 0; // End of program
}

 Output

Enter your numeric grade (0-100): 87
Your letter grade is: B

Share this C++ Exercise


More C++ Programming Exercises of Advanced Conditional Structures in C++

Explore our set of C++ Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C++. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C++.

  • Check if Two Strings Are Anagrams in C++

    In this C++ exercise, you will develop a program that checks whether two given strings are anagrams of each other. An anagram is formed by rearranging the letters of one word to pr...

  • Calculate Ticket Price Based on User's Age in C++

    In this C++ exercise, you will create a program that calculates the price of a ticket based on the age of the user. Different age groups are often charged different prices for even...

  • ATM Simulator with Multiple Operations in C++

    In this C++ exercise, you will create a simple simulation of an ATM (Automated Teller Machine). The program will allow the user to perform basic banking operations such as checking...

  • Guess the Number Game (1-100) in C++

    In this exercise, you will implement a program that simulates a simple number guessing game. The program will generate a random number between 1 and 100, and the player will attemp...

  • Calculate the Price with Discount Based on Total Purchase in C++

    In this exercise, you will create a program that calculates the total price of a purchase, applying a discount based on the total amount. The program will prompt the user to enter ...

  • Check if a Word is a Palindrome in C++

    In this exercise, you will write a program that checks whether a given word is a palindrome. A palindrome is a word that reads the same forwards and backwards, such as "radar" or "...