#include #include #include #include #include using namespace std; int main(int argc, char* argv[]) { if ( argc != 2 ) { cerr << "ERROR: solution file argument missing." << endl; return 0; } ifstream ifs(argv[1]); if ( ! ifs ) { cerr << "ERROR: solution file could not be opened." << endl; return 0; } string given_answer, rest_of_line; cout << "Please enter given answer: "; cin >> given_answer; unsigned int i = 0; int score = 0; try { char correct_answer; while ( ifs >> correct_answer ) { if ( tolower(given_answer.at(i++)) == tolower(correct_answer) ) ++score; ifs.ignore(numeric_limits::max(), '\n'); } } catch (out_of_range& e) { cout << "WARNING: too few questions answered." << endl; } if ( given_answer.size() > i ) { cout << "WARNING: too many questions answered." << endl; } cout << score << " point(s)." << endl; return 0; }