1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
// asg7a.cpp
// Written by
// Fall 2010
// Purpose: Proper Words
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void processAnswers(char, char, int);
int main()
{
const int size = 20; // Array size
char answers[size] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D',
'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'},
studentAnswers[size];// Holds the line of user input
int count = 0;
int sCount = 0;
int incorrect = 0;
bool space = true;
for (count = 0; count < size; count++)
{
if (!space) // extra code to help with spacing
{
cout << "\n";
}
cout << "What is your score for test " << (count + 1) << " ? ";
cin >> studentAnswers[count];
while (studentAnswers[count] != 'A' && studentAnswers[count] != 'B' &&
studentAnswers[count] != 'C' && studentAnswers[count] != 'D')
{
cout << "You must enter A, B, C, or D. ";
cin >> studentAnswers[count];
space = false;
}
}
processAnswers(studentAnswers[count], answers[size], size);
system("pause");
return 0;
}
void processAnswers(char studentAnswers[], char answers[], int size)
{
int incorrect = 0;
for (int sCount = 0; sCount < size; sCount++)
{
if (studentAnswers[sCount] != answers[sCount])
{
cout << incorrect++;
}
}
}
|