[ create a new paste ] login | about

Link: http://codepad.org/1U81H77e    [ raw code | output | fork ]

pjvangemmeren - C++, pasted on Feb 23:
#include <iostream>
using namespace std;

int main()
{
    int correctAnswers;
    int questions;
    int testScore;
    char grade;

    cout << "Enter the number of questions on the test\n";
    cin >> questions;
    cout << "Enter the number of questions that you answered correctly.";
    cin >> correctAnswers;

    testScore = (correctAnswers / questions) * 100;

    if (testScore < 60)
        grade = 'F';
    else if (testScore < 70)
        grade = 'D';
    else if (testScore < 80)
        grade = 'C';
    else if (testScore < 90)
        grade = 'B';
    else if (testScore <= 100)
        grade = 'A';
    else if (testScore > 100)
        grade = '?';

    cout << "Your grade is " << grade << ".\n";
    return 0;
}


Output:
1
2
3
Enter the number of questions on the test

Floating point exception


Create a new paste based on this one


Comments: