I made this program but I need to figure out how to exit the program
if the user does not input A,B,C,D, after three attempts. I'm new at building
programs and I would be grateful for some help!
#include <iostream>
using namespace std;
char studentAnswers(int);
int main()
{
int i;
int correct = 0;
int incorrect = 0;
char *correctAnswers = "BDAACABACD"; // answers
char grade[10]; // student answer array declaration
for(i = 0; i < 10; i++) //input answers
{
grade = studentAnswers(i);
}
for(i = 0; i < 10; i++)
{
if(grade == correctAnswers)
{
correct++; //correct answer counter
}
else
{
incorrect++; //incorrect answer counter
}
}
if (correct >= 8)
{
cout << "\nCongratulations!\n";
cout << "You have passed exam.\n";
cout << "Total number of correct answers: < " << correct << " >\n";
cout << "Total number of incorrect answers: < " << incorrect << " >\n";
}
else
{
cout << "Sorry. You have not passed the exam.\n";
cout << "Total number of correct answers: < " << correct << " >\n";
cout << "Total number of incorrect answers: < " << incorrect << " >\n";
}
return 0;
}
char studentAnswers(int i)
{
char choice;
cout << "Please enter your choice for Question " << i+1 << endl;
cin >> choice;
choice = toupper(choice);
while (choice != 'A' && choice != 'B'&& choice != 'C' && choice != 'D')
{
cout << "You must enter A, B, C, or D.\n";
cin >> choice;
}
return choice;
}