Skip to content

Instantly share code, notes, and snippets.

@conqp
Last active May 4, 2021 12:45
Show Gist options
  • Save conqp/b29d76c9bb9a075139e8fc4c440b8cf2 to your computer and use it in GitHub Desktop.
Save conqp/b29d76c9bb9a075139e8fc4c440b8cf2 to your computer and use it in GitHub Desktop.
Check whether you passed an exam
#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