-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionaire.cpp
More file actions
71 lines (59 loc) · 1.54 KB
/
Copy pathQuestionaire.cpp
File metadata and controls
71 lines (59 loc) · 1.54 KB
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
#include <iostream>
#include <string>
using namespace std;
// Replace with main to run.
int Questionaire()
{
int score = 0;
enum QA
{
Question,
AnswerA,
AnswerB,
AnswerC,
AnswerD,
COUNT
};
// Quiz data: 3 questions, each with 4 answers
string data[3][COUNT] = {
{"What is the capital of France?", "Paris", "London", "Berlin", "Madrid"},
{"What is 2 + 2?", "3", "5", "4", "22"},
{"What is the largest planet in our solar system?", "Earth", "Mars", "Saturn", "Jupiter"}};
// Correct answers: by full string and by letter
string correctAnswers[2][3] = {
{"Paris", "4", "Jupiter"},
{"A", "C", "D"}};
cout << "Quiz Time!" << endl;
cout << "Answer the following questions by entering A, B, C, or D." << endl;
for (int i = 0; i < 3; i++)
{
cout << "\n"
<< data[i][Question] << "\n\n";
cout << "A. " << data[i][AnswerA] << endl;
cout << "B. " << data[i][AnswerB] << endl;
cout << "C. " << data[i][AnswerC] << endl;
cout << "D. " << data[i][AnswerD] << endl;
string reply;
cout << "\nYour answer: ";
getline(cin, reply);
while (reply.empty())
{
cout << "Please provide an answer: ";
getline(cin, reply);
}
// Normalize input to uppercase
if (reply.size() == 1)
reply[0] = toupper(reply[0]);
// Check if reply matches correct answer
if (reply == correctAnswers[0][i] || reply == correctAnswers[1][i])
{
score += 1;
}
else if (reply != correctAnswers[0][i] || reply != correctAnswers[1][i])
{
score -= 1;
}
}
cout << "\nFinal Score: " << score << "Points" << endl;
return 0;
}