How do you use five questions in a quiz game for two players


#include <iostream>
# include <string>
# include <fstream>
bool validQuestion(char Question1);

using namespace std;
{
char response; //Get response from players
char Question1, Question2, Question3, Question4, Question5;
bool valid = false;
int score1 = 0;
int score2 = 0;
string name1; //name of player1
string name2; // name of player2
cout << "Enter Y/y to play the game, then press the enter key";
cin >> response;
cout << endl;

if (response == 'Y' || response == 'y')
Questions();
while (response == 'Y' || response == 'y')

{
do
{
cout << name1 << "please enter your answers for each question.\n"
<< "Your answers can be entered in uppercase or lowercase letters.\n"
<< "Press the enter key after selecting your choice\n";
cin >> Question1;
cout << endl;
valid = validQuestion(Question1);
}
while (valid != true);

do
{
cout << name2 << "please enter your answers for each question.\n"
<< "Your answers can be entered in uppercase or lowercase letters.\n"
<< "Press the enter key after selecting your choice\n";
cin >> Question1;
cout << endl;
valid = validQuestion(Question1);
}
while (valid != true);
cout << "Here is where we find out who the \"Smartest\" and \"Dumbest\" is.\n"
<< "If " << name1 << " is the \"Smartest\" then we know that " << name2
<< "is the \"Dumbest\" and if " << name2 << " is the \"Smartest\" then\n"
<< "we know that " << name1 << " is the \"Dumbest.\"" << endl;
cout << endl;
}
cin.get();
return 0;
}

bool validQuestion(char Question1) //function call to validQuestions
{
bool verify;
switch (Question1)
{
case 'A':
cout << "Wrong Answer" << endl;
break;
case 'a':
cout << "Wrong Answer" << endl;
break;
case 'B':
cout << "Wrong Answer" << endl;
break;
case 'b':
cout << "Wrong Answer" << endl;
break;
case 'C':
cout << "This is the correct answer" << endl;
break;
case 'c':
cout << "This is the correct answer" << endl;
break;
case 'D':
cout << "Wrong Answer" << endl;
break;
case 'd':
cout << "Wrong Answer" << endl;
break;
verify = true;
return verify;
default:
cout << "You entered a invalid selection - please try again" << endl;
verify = false;
return verify;
}
}

// I have more code in this program of course and have thus far got to this point. My problem is is that I want to go to question 2, 3, 4, and 5 still and do not know if I need a switch structure for each question. Each case in the switch structure is for multiple choice answers for a, b, c, and d. All five questions in this trivia game are multiple choice questions. After all the questions are answered by each player I have to show who got the highest score out of five questions.
To all computer master wizards I beg for knowledge for a soluition as after all,
"I am the knightRider and kit is in the shop for vechile repairs.
"I am the knightRider and kit is in the shop for vechile repairs.
can't you use one of your two friends, the programmer ones?

Also please use [co de][/co de] tags, though do remove the spaces, it makes your program easier to read.

#include <iostream>
# include <string>
# include <fstream>
bool validQuestion(char Question1);

using namespace std;
{
char response; //Get response from players
char Question1, Question2, Question3, Question4, Question5;
bool valid = false;
int score1 = 0;
int score2 = 0;
string name1; //name of player1
string name2; // name of player2
cout << "Enter Y/y to play the game, then press the enter key";
cin >> response;
cout << endl;

if (response == 'Y' || response == 'y')
Questions();
while (response == 'Y' || response == 'y')

{
do
{
cout << name1 << "please enter your answers for each question.\n"
<< "Your answers can be entered in uppercase or lowercase letters.\n"
<< "Press the enter key after selecting your choice\n";
cin >> Question1;
cout << endl;
valid = validQuestion(Question1);
}
while (valid != true);

do
{
cout << name2 << "please enter your answers for each question.\n"
<< "Your answers can be entered in uppercase or lowercase letters.\n"
<< "Press the enter key after selecting your choice\n";
cin >> Question1;
cout << endl;
valid = validQuestion(Question1);
}
while (valid != true);
cout << "Here is where we find out who the \"Smartest\" and \"Dumbest\" is.\n"
<< "If " << name1 << " is the \"Smartest\" then we know that " << name2
<< "is the \"Dumbest\" and if " << name2 << " is the \"Smartest\" then\n"
<< "we know that " << name1 << " is the \"Dumbest.\"" << endl;
cout << endl;
}
cin.get();
return 0;
}

bool validQuestion(char Question1) //function call to validQuestions
{
bool verify;
switch (Question1)
{
case 'A':
cout << "Wrong Answer" << endl;
break;
case 'a':
cout << "Wrong Answer" << endl;
break;
case 'B':
cout << "Wrong Answer" << endl;
break;
case 'b':
cout << "Wrong Answer" << endl;
break;
case 'C':
cout << "This is the correct answer" << endl;
break;
case 'c':
cout << "This is the correct answer" << endl;
break;
case 'D':
cout << "Wrong Answer" << endl;
break;
case 'd':
cout << "Wrong Answer" << endl;
break;
verify = true;
return verify;
default:
cout << "You entered a invalid selection - please try again" << endl;
verify = false;
return verify;
}
}

// I have more code in this program of course and have thus far got to this point. My problem is is that I want to go to question 2, 3, 4, and 5 still and do not know if I need a switch structure for each question. Each case in the switch structure is for multiple choice answers for a, b, c, and d. All five questions in this trivia game are multiple choice questions. After all the questions are answered by each player I have to show who got the highest score out of five questions.
To all computer master wizards I beg for knowledge for a soluition as after all,
"I am the knightRider and kit is in the shop for vechile repairs.
USE THE CODE TAGS IT MAKES IT EASIER TO READ YOUR CODE.
Look, put your code in between the [code] tags. Like this:
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
#include <iostream>
# include <string>
# include <fstream>

using namespace std;

bool validQuestion(char Question1);
{
    char response; //Get response from players
    char Question1, Question2, Question3, Question4, Question5;
    bool valid = false;
    int score1 = 0;
    int score2 = 0;
    string name1; //name of player1
    string name2; // name of player2
    cout << "Enter Y/y to play the game, then press the enter key";
    cin >> response;
    cout << endl;

    if (response == 'Y' || response == 'y')
        Questions();
    while (response == 'Y' || response == 'y')
    {
        do
        {
            cout << name1 << "please enter your answers for each question.\n"
                   << "Your answers can be entered in uppercase or lowercase letters.\n"
                   << "Press the enter key after selecting your choice\n";
            cin >> Question1;
            cout << endl;
            valid = validQuestion(Question1);
        } while (valid != true);
        do
        {
            cout << name2 << "please enter your answers for each question.\n"
                    << "Your answers can be entered in uppercase or lowercase letters.\n"
                    << "Press the enter key after selecting your choice\n";
            cin >> Question1;
            cout << endl;
            valid = validQuestion(Question1);
        } while (valid != true);
        cout << "Here is where we find out who the \"Smartest\" and \"Dumbest\" is.\n"
                << "If " << name1 << " is the \"Smartest\" then we know that " << name2
                << "is the \"Dumbest\" and if " << name2 << " is the \"Smartest\" then\n"
                << "we know that " << name1 << " is the \"Dumbest.\"" << endl;
        cout << endl;
    }
    cin.get();
    return 0;
}

bool validQuestion(char Question1) //function call to validQuestions
{
    bool verify;
    switch (Question1)
    {
        case 'A':
            cout << "Wrong Answer" << endl;
            break;
        case 'a':
            cout << "Wrong Answer" << endl;
            break;
        case 'B':
            cout << "Wrong Answer" << endl;
            break;
        case 'b':
            cout << "Wrong Answer" << endl;
            break;
        case 'C':
            cout << "This is the correct answer" << endl;
            break;
        case 'c':
            cout << "This is the correct answer" << endl;
            break;
        case 'D':
            cout << "Wrong Answer" << endl;
            break;
        case 'd':
            cout << "Wrong Answer" << endl;
            verify = true;
            return verify;
            break;
        default:
            cout << "You entered a invalid selection - please try again" << endl;
            verify = false;
            return verify;
            break;
        }
}


You need break statements. You also have the same method on there twice... Confusing.
Last edited on
Topic archived. No new replies allowed.