Trying to make a multiple choice question

  c++, choice, duplicates
#include <iostream>

using namespace std;

int main() {
  /**
  4 variants
  3 correct
  a b c d
  d is incorrecy
  if an answer is reapeted, it needs to say
      "Answer *a/b/c/d* has been already introduced"
  **/
  cout << "Which ones are correct?: a) b) c) d) n";
  // for the sake of the example, only A B and C are correct
  string answer;
  int numberOfCorrectAnswers = 0;
  bool correct = true;

  while (true) {
    cin >> answer;
    if (answer == "a" || answer == "b" || answer == "c")
      numberOfCorrectAnswers++;

    else if (answer == "d")
      correct = false;

    if (answer == "Done")
      break;

    if (answer != "a" && answer != "b" && answer != "c" && answer != "d") {
      cout << "Input available answer!n";
    }
  }

  if (correct == true && numberOfCorrectAnswers == 3)
    cout << numberOfCorrectAnswers;
  else
    cout << "Incorrect answers!";
  return 0;
}

I am trying to make a multiple choice question, yet I can’t figure out how to make it so when I input an answer twice, it doesn’t take it as correct and instead asks for a second input.

Example: a a b Done (incorrect)

Source: Windows Questions C++

LEAVE A COMMENT