problem

can someone please tell me what I am doing wrong! the second part of this program on the drivers license exam is suppose to display the total of incorrect and correct answers the user got right and wrong, but it is not showing how many they get wrong and right.

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
   int choice;//starts menu
   const int empId = 7; //array size 
   int workers[empId] = {5658846, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489}; //employees numbers
   int hours[empId]; //holds hours
   double payRate[empId]; //holds payrate
   
   // Display menu choices
   cout << "Select a menu choice: " << endl;
   cout << "1. Payroll" << endl;
   cout << "2. Driver's License Exam" << endl;
   cout << "3. Quit" << endl;
   cout << "Please enter your choice: ";
   cin >> choice;
   
   if (choice == 1)
   {
	//Gets employees hours and payrates
        for (int index = 0; index < empId; index++)
        {
            cout << "Please enter the hours worked by employee # " << (index+1) << " (ID = " << workers[index] << " ): ";
            cin >> hours[index];
            cout << "Please enter the pay rate for employee # " << (index+1) << " (ID = " << workers[index] << " ): ";
            cin >> payRate[index];
            //asks to re-enter hours if negative
            if (hours[index] < 0)
            {
                cout << "Hours cannot be negative. Please re-enter hours: ";
                cin >> hours[index];
            }
	//asks to re-enter payrate if it is less than 6        
            if (payRate[index] < 6)
            {
                cout << "The pay rate cannot be les than 6. Please re-enter pay rate: ";
                cin >> payRate[index];
            }
        }
        
    // Displays employees # and wages 
    for (int index = 0; index < empId; index++)
    {
        cout << fixed << showpoint << setprecision(2);
	//Calculates and displays wages
        double wages = hours[index] * payRate[index];
        cout << "Employee #" << (index + 1);
        cout << "earned: $" << wages <<  endl << endl;
    }
    }

   	const int SIZE = 20; //size of array
	char studentAnswers[SIZE];//student answer
	char correctAnswers[SIZE] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'}; //Correct answers
	int correct = 0; //variable to count correct answers
	int incorrectAnswers = 0; //variable to count incorrect answers  

	if (choice == 2)
	{
		// Gets the answers for each question
		cout << "Please enter your answers to your Driver's License Exam questions. " << endl;
		for (int index = 0; index < SIZE; index++)
		{
			cout <<"Enter answer for question # " << index + 1 << " : ";
			cin >> studentAnswers[index];
		//Checks if user entered correct letter
		if (studentAnswers[index] == 'A' && studentAnswers[index] == 'B' && studentAnswers[index] == 'C' && studentAnswers[index] == 'D')
		{
			cout << "A,B,C, and D are the only valid inputs. Please input the answer again." << endl;
			incorrectAnswers++;
			--index;

		}
	}
	//Calculates if student passed exam
	for (int index = 0; index < SIZE; index++)
	{
		if (studentAnswers[index] == correctAnswers[index])

			correct++;
	}
	//Displays wether the student passed the exam
	if (correct >= 15)
	{
		cout << "You have passed the exam." << endl;
	}
	else 
		cout << "You have failed the exam." << endl;
		//Displays the total of correct and incorrect questions	
		cout << "Total number of correct answers: " << correct << endl;
		cout << "Total number of incorrect answers: " << 20 - correct << endl;
	}
		while (correct >= 15);

	if (choice == 3)
	{
		cout << "Good-Bye" << endl;
	}
   
   return 0;
}
Last edited on
if (studentAnswers[index] == 'A' && studentAnswers[index] == 'B' && studentAnswers[index] == 'C' && studentAnswers[index] == 'D')
This condition will never be true.

Why do you count 'E' as an incorrect answer, but ask for it again?

Are you not allowed to use functions?
Topic archived. No new replies allowed.