Reputation: 376
Alright, so I've got a simple online programming assignment that's checked by an automatic grading thingy. Most have been pretty easy, but I can't get this assignment to work. Here's the prompt and my code. I have a feeling I'm missing something fairly simple. Thanks for your help.
Students just took a short, two question, multiple choice quiz. Both questions needed to >be answered correctly to receive credit. As their grader, you must determine whether >students got credit or not. The correct answers were A and D.
Input
The students' answers, sepated by a space.
Output
"Credit" or "No credit"
Example
Input: A C
Output: No credit
My code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
cin >> input;
if (input == "A D")
{
cout << "Credit";
}
else
{
cout << "No credit";
}
return 0;
}
Upvotes: 0
Views: 123
Reputation: 96855
std::cin
will stop searching for input when it hits a new line \n
or whitespace. In order to get the entire line of input, use std::getline
:
std::string input;
std::getline(std::cin, input);
Upvotes: 2