Implement Grading System with If-Else

CBeginner
Practice Now

Introduction

In this challenge, a local high school needs a digital grading system to automatically convert numerical scores into letter grades. The goal is to practice using multi-branch if-else statements to create a simple grade conversion program that handles scores from 0 to 100 with appropriate grade classifications.

This is a Challenge, which differs from a Guided Lab in that you need to try to complete the challenge task independently, rather than following the steps of a lab to learn. Challenges are usually a bit difficult. If you find it difficult, you can discuss with Labby or check the solution. Historical data shows that this is a beginner level challenge with a 98% pass rate. It has received a 100% positive review rate from learners.

Implement Grading System with If-Else

A local high school needs a digital grading system to automatically convert numerical scores into letter grades. This challenge will help you practice using multi-branch if-else statements to create a simple grade conversion program.

Tasks

  • Create a C++ program that converts numerical scores to letter grades
  • Implement a multi-branch if-else statement to map scores to grades
  • Handle scores from 0 to 100 with appropriate grade classifications

Requirements

  • Create a file named grade_converter.cpp in the ~/project directory
  • Use a multi-branch if-else statement for grade conversion
  • Define grade ranges as follows:
    • 90-100: A
    • 80-89: B
    • 70-79: C
    • 60-69: D
    • 0-59: F
  • Program should take a numerical score as input and output the corresponding letter grade
  • Use std::cout to display the final grade

Examples

After implementing the grade conversion logic, you can test the program by running it and entering different numerical scores to see the corresponding letter grades.

## Compile the program
g++ -o grade_converter grade_converter.cpp

## Run the program
./grade_converter
## Test Case 1: A Grade
Enter your numerical score (0-100): 95
A

## Test Case 2: C Grade
Enter your numerical score (0-100): 75
C

## Test Case 3: F Grade
Enter your numerical score (0-100): 55
F

## Test Case 4: Invalid Input
Enter your numerical score (0-100): 150
Invalid score. Please enter a score between 0 and 100.

Hints

  • Remember to use if-else statements with comparison operators
  • Check conditions from highest to lowest grade ranges
  • Use std::cin to get user input
  • Ensure your conditions cover all possible score inputs
✨ Check Solution and Practice

Summary

In summary, this challenge requires the implementation of a C++ program that converts numerical scores to letter grades using a multi-branch if-else statement. The program should handle scores from 0 to 100 and map them to the appropriate grade classifications: A (90-100), B (80-89), C (70-79), D (60-69), and F (0-59). The program should take a numerical score as input and output the corresponding letter grade using std::cout.