Last active
May 4, 2021 12:45
-
-
Save conqp/b29d76c9bb9a075139e8fc4c440b8cf2 to your computer and use it in GitHub Desktop.
Check whether you passed an exam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using std::cin; | |
using std::cout; | |
using std::endl; | |
using std::string; | |
static unsigned short readMarks(string const & prompt) | |
{ | |
unsigned short marks; | |
cout << prompt; | |
cin >> marks; | |
return marks; | |
} | |
static unsigned short readMarks() | |
{ | |
return readMarks("Enter your marks: "); | |
} | |
static bool hasPassed(unsigned short marks, unsigned short failureThreshold) | |
{ | |
return marks > failureThreshold; | |
} | |
static bool hasPassed(unsigned short marks) | |
{ | |
return hasPassed(marks, 40); | |
} | |
static void printResult(bool passed) | |
{ | |
cout << "You " << (passed ? "passed" : "failed") << " the exam." << endl; | |
} | |
int main() | |
{ | |
printResult(hasPassed(readMarks())); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment