Repository navigation
Expand file tree
/
Copy pathtriviagame.cpp
More file actions
62 lines (51 loc) · 1.41 KB
/
Copy pathtriviagame.cpp
File metadata and controls
62 lines (51 loc) · 1.41 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
/* A simple trivia game
to learn working with functions
*/
#include <iostream>
using namespace std;
void no1()
{
char answer = 'B'; // the right answer
char guess; // to hold input from user
// The first question
cout << "Which of these is true about the sleep of zebras ?" << endl;
cout << "A All of these" << endl;
cout << "B They sleep standing up" << endl;
cout << "C They fall asleep every 5 to 6 hours" << endl;
cout << "D They need more than 12 hours of sleep a day" << endl;
cin >> guess; // promt user for answer
// check if answer is correct
if(guess == answer) {
cout << "correct\n";
}else if(guess == 'A' || 'C' || 'D'){
cout << "No, Wrong answer!";
}else{ // incase usser enters an answer not available
cout << "invalid input";
}
}
// another question
void no2()
{
char answer = 'B';
char guess;
cout << "A farmer had 12 sheep and 3 cows." << endl;
cout << "All of the animals died except 9 sheep died." << endl;
cout << "How many animals did he have left in his farm ?" << endl;
cout << "A 5 cows and 1 sheep" << endl;
cout << "B 9 sheep" << endl;
cout << "C 2 cows" << endl;
cout << "D None" << endl;
cin >> guess;
if(guess == answer) {
cout << "correct\n";
}else if(guess == 'A' || 'C' || 'D'){
cout << "No, Wrong answer!";
}else{
cout << "invalid input";
}
}
int main()
{
no1(); // calling the function
no2(); // calling the second function
}