I'm in an 'Intro to C++' class, and have an assignment to write a program that basically takes answers to a test, and grades it. I finished writing it, but as I was going through and cleaning up errors, I got a 'Signed/Unsigned Mismatch' error. I've never run into this before and was looking for some help. The error is in the for loop at the very bottom of the last function.
I figure its something to do with that vector size comparison? I just learned about vectors today, and this is my first use of them :lol
Thanks!
Code:
#include <iostream>
#include <vector>
using namespace std;
void getAnswers(char [], int);
void standardAnswers(char [], int);
void gradeTest(char [], char [], int, vector<int>);
void outputGrade(vector<int>, int);
int main()
{
const int SIZE = 20;
char testAnswers[SIZE] = { 'B', 'D', 'A', 'A', 'C',
'A', 'B', 'A', 'C', 'D',
'B', 'C', 'D', 'A', 'D',
'C', 'C', 'B', 'D', 'A' };
char testStudent[SIZE];
vector<int> incorrect;
cout << "This program will let you enter your answers for the Driver's \n"
<< "License Exam, and give you a grade. Enter your answers below.\n";
cout << "Only A, B, C, and D are valid answers.\n";
getAnswers(testStudent, SIZE);
standardAnswers(testStudent, SIZE);
gradeTest(testAnswers, testStudent, SIZE, incorrect);
outputGrade(incorrect, SIZE);
return 0;
}
void getAnswers(char answers[], int size)
{
for (int count = 0; count < size; count++)
{
cout << "Question " << (count + 1) << ": ";
cin >> answers[count];
while (answers[count] != 'A' && answers[count] != 'a' &&
answers[count] != 'B' && answers[count] != 'b' &&
answers[count] != 'C' && answers[count] != 'c' &&
answers[count] != 'D' && answers[count] != 'd')
{
cout << "ERROR: Only A,B,C, and D are valid.\n";
cout << "Question " << (count + 1) << ": ";
cin >> answers[count];
}
}
}
void standardAnswers(char answers[], int size)
{
for (int count = 0; count < size; count++)
{
switch (answers[count])
{
case 'a': answers[count] = 'A';
case 'b': answers[count] = 'B';
case 'c': answers[count] = 'C';
case 'd': answers[count] = 'D';
}
}
}
void gradeTest(char testAnswers[], char testStudent[], int size, vector<int> incorrect)
{
for (int count = 0; count < size; count++)
{
if (testAnswers[count] != testStudent[count])
incorrect.push_back(count + 1);
}
}
void outputGrade(vector<int> incorrect, int questions)
{
if (incorrect.size() <= 5)
cout << "You passed the exam! Congratulation!\n";
else
cout << "You FAILED the exam.\n";
cout << "You answered " << (questions - incorrect.size()) << " questions correctly, and\n"
<< incorrect.size() << " questions incorrectly.\n";
cout << "The questions you answered incorrectly were numbers ";
for (int i = 0; i < (incorrect.size() - 1); i++) //signed/unsigned mismatch here
cout << incorrect[i] << ", ";
cout << "and " << incorrect[incorrect.size] << ".\n";
}
I figure its something to do with that vector size comparison? I just learned about vectors today, and this is my first use of them :lol
Thanks!