Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.8 kB
9
Indexable
Never
#include <iostream>
#include <fstream>
#include <string>

using namespace std;



//########## 1 2 3 4 5 6 7 8 9 10

const char ANSWERS[10] = { 'D' , 'C' , 'D' , 'A' , 'A' , 'A' , 'A' , 'D' , 'A' , 'D' };

void userAnswers(string);

int main() {

  string questions;

  string arAnswers[50];

  int a = 0, c = 0, answerNum[10];

  cout << "\nEnter the file name (with extension): ";

  cin >> questions;

  cout<<endl;

  string myText;

  // userAnswers(fileName);

  ifstream fileIn; //Read in from file

  fileIn.open(questions);

  if (fileIn.is_open()) {

    while (getline (fileIn, myText)) {

      arAnswers[a] = myText;
      a++;

    }

  }
  else {
    cout << "\nERROR: File not found!"; //file validation
  }

  a = 0;
  char ch;
  int x = 5;
  int y = 0;
  for (int b = 0; b < 10; b++) {

    while(x--){
      cout<<arAnswers[y]<<endl;
      y++;
    }
    cout << "\nEnter the answer for question #" << b + 1 << ": ";

    cin >> ch;

    cout<<endl;

    while (ch < 65 || ch > 68) { //Answers validations

      cout << endl << "ERROR: Invalid Answer! \nTry Again!";

      cout << "\nEnter the answer for question #" << b+1 << ": ";

      cin>> ch;
        
    }

    if (ch == ANSWERS[b]) {

      answerNum[a] = b + 1;

      a++;

    }

    else{
      c++;
    }
    x = 5;

  }//Outputs:

  if (a > 14)cout << endl << "You've passed the test!";

  else cout << endl << "You've failed the test!";

  cout << "\nTotal correct answers: " << a;

  cout << "\nTotal incorrect answers: " << c << endl << "Correct answers are: ";

    for (int b = 0; b < a; b++) {

      cout << endl << answerNum[b] << endl;

    }

  //system("pause");

  return 0;

}