0% found this document useful (0 votes)
32 views

C++ Sample On Switch

The program prompts the user to enter a grade between A-F. It uses a switch statement to output different messages depending on the grade entered. If an invalid grade is entered, it prompts the user to try again. The program then displays the grade that was entered.

Uploaded by

Nass
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

C++ Sample On Switch

The program prompts the user to enter a grade between A-F. It uses a switch statement to output different messages depending on the grade entered. If an invalid grade is entered, it prompts the user to try again. The program then displays the grade that was entered.

Uploaded by

Nass
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include 

<iostream>
using namespace std;
int main()
{
    char grade;
    grade = 'A', 'B', 'C', 'D', 'E', 'F';
    AGAIN:
    cout << "Please enter your grade: ";
    cin >> grade;

    switch (grade)
    {
    case 'A':
    {
        cout << "Excellent!" << endl;
        break;
    }
    case 'B':
    case 'C':
    {
        cout << "Well done!" << endl;
    }
    break;
    case 'D':
    {
        cout << "You passed!" << endl;
    }
    break;
    case 'E':
    {
        cout << "You failed!" << endl;
    }
    break;
    case 'F':
    {
        cout << "Better try again!" << endl;
    }
    break;

    default:
    {
        cout << "Invalid grade" << endl;
        goto AGAIN;
        break;
    }
    }
    if (grade == 'A', 'B', 'C', 'D', 'E', 'F')
    {
        cout << "Your grade is " << grade << endl;
    }
    else
        cout << "please enter again";
    return 0;
}

You might also like