Hello all. I'm trying to write a program that will compare 2 one-dimensional arrays and then generate an output telling how many differences there are between the two. Essentially the program is for prompting a user to enter in the answers to a 10 question test. I've stored the correct answers in the first array and the user will store their answers in the second array. I'm stuck on how to write the loop portion because the answers are alphabetical not numerical. What kind of loop can I use to compare characters rather than numbers? Here is what I have so far:
#include <iostream> #include <string>
usingnamespace std;
char A, B, C, D;
char correct[10] = 'B', 'A', 'C', 'D', 'C', 'D', 'B', 'A', 'B', 'B' };
// Correct Answers for Test
char ans[10];
int main ()
{
string name;
cout << "Welcome to the Department of Motor Vehicles";
cout << "\n";
cout << "Please enter your name: "; getline(cin, name);
cout << "\n";
// This is where I am prompting the user for their answers
cout << "Please enter the answer for question 1: ";
cin >> ans[0];
cout << "\n";
cout << "Please enter the answer for question 2: ";
cin >> ans[1];
cout << "\n";
cout << "Please enter the answer for question 3: ";
cin >> ans[2];
cout << "\n";
cout << "Please enter the answer for question 4: ";
cin >> ans[3];
cout << "\n";
cout << "Please enter the answer for question 5: ";
cin >> ans[4];
cout << "\n";
cout << "Please enter the answer for question 6: ";
cin >> ans[5];
cout << "\n";
cout << "Please enter the answer for question 7: ";
cin >> ans[6];
cout << "\n";
cout << "Please enter the answer for question 8: ";
cin >> ans[7];
cout << "\n";
cout << "Please enter the answer for question 9: ";
cin >> ans[8];
cout << "\n";
cout << "Please enter the answer for question 10: ";
cin >> ans[9];
if ( correct == ans)
cout << name << " you passed the test!";
else
cout << name << " you failed the test!";
return 0;
}
Is there a way to tweak the If statement to say answer array has to match at least 8 of the answers from the correct answer array to output that the person passed the test. If they matched anything less it should tell them they failed.
This include is very peculiar. I believe that it should only accept the first include and the string inclusion is ignored. You should put them on their own separate lines. It's kind of funny that this works (which is probably because iostream itself includes string).
I actually have iostream and string on seperate lines but for some reason when I posted code it moved them onto the same line.
as far as the char A,B,C,D; goes it kept erroring out on me, but then again it was probably something else I was doing. I'll try to remove it now and see what happens. Thanks Seymore!