0

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;
}
1
  • You should use a string compare function. Commented Sep 25, 2013 at 1:10

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I knew I was missing something simple but couldn't figure out what it was.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.