Questions Game. Help Needed

I know this are quite simple errors but I'm having trouble resolving them. Any help would be appreciated.

Header File
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
#ifndef QUESTIONS_H
#define QUESTIONS_H
#include "Questions.h"
#include <string>

class Questions
{
	private:
		string questions;
		string answer1;
		string answer2;
		string answer3;
		string answer4;
		int correctAnswer;

	public:
		void setQuestions(string q)
		{
			questions = q;
		}

		void setAnswer1(string a1)
		{
			answer1 = a1;
		}

		void setAnswer2(string a2)
		{
			answer2 = a2;
		}

		void setAnswer3(string a3)
		{
			answer3 = a3;
		}

		void setAnswer4(string a4)
		{
			answer4 = a4;
		}

		void setCorrectAnswer(int c)
		{
			correctAnswer = c;
		}

		string getQuestions()
		{
			return questions;
		}

		string getAnswer1()
		{
			return answer1;
		}

		string getAnswer2()
		{
			return answer2;
		}

		string getAnswer3()
		{
			return answer3;
		}

		string getAnswer4()
		{
			return answer4;
		}

		int getCorrectAnswer()
		{
			return correctAnswer;
		}
};

#endif 


Main
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
#include <string>
#include <iomanip>
#include "Questions.h"
using namespace std;

char again;
void questionAnswer(questions[], int);

int main()
{
	do
	{
		questions game[10];
		int count = 0;
		int choice1, choice2;
		int points1 = 0;
		int points2 = 0;

		cout << "Trivia Game" << endl;
		cout << "-----------" << endl << endl;

		game[0].setQuestion("What color is the sky?");
			game[0].setAnswer1("1. Yellow");
			game[0].setAnswer2("2. Blue");
			game[0].setAnswer3("3. Purple");
			game[0].setAnswer4("4. Red");
			game[0].setCorrect(2);

		game[1].setQuestion("What color is the sky?");
			game[1].setAnswer1("1. Yellow");
			game[1].setAnswer2("2. Blue");
			game[1].setAnswer3("3. Purple");
			game[1].setAnswer4("4. Red");
			game[1].setCorrect(2);

		game[2].setQuestion("What color is the sky?");
			game[2].setAnswer1("1. Yellow");
			game[2].setAnswer2("2. Blue");
			game[2].setAnswer3("3. Purple");
			game[2].setAnswer4("4. Red");
			game[2].setCorrect(2);

		game[3].setQuestion("What color is the sky?");
			game[3].setAnswer1("1. Yellow");
			game[3].setAnswer2("2. Blue");
			game[3].setAnswer3("3. Purple");
			game[3].setAnswer4("4. Red");
			game[3].setCorrect(2);

		game[4].setQuestion("What color is the sky?");
			game[4].setAnswer1("1. Yellow");
			game[4].setAnswer2("2. Blue");
			game[4].setAnswer3("3. Purple");
			game[4].setAnswer4("4. Red");
			game[4].setCorrect(2);

		game[5].setQuestion("What color is the sky?");
			game[5].setAnswer1("1. Yellow");
			game[5].setAnswer2("2. Blue");
			game[5].setAnswer3("3. Purple");
			game[5].setAnswer4("4. Red");
			game[5].setCorrect(2);

		game[6].setQuestion("What color is the sky?");
			game[6].setAnswer1("1. Yellow");
			game[6].setAnswer2("2. Blue");
			game[6].setAnswer3("3. Purple");
			game[6].setAnswer4("4. Red");
			game[6].setCorrect(2);

		game[7].setQuestion("What color is the sky?");
			game[7].setAnswer1("1. Yellow");
			game[7].setAnswer2("2. Blue");
			game[7].setAnswer3("3. Purple");
			game[7].setAnswer4("4. Red");
			game[7].setCorrect(2);

		game[8].setQuestion("What color is the sky?");
			game[8].setAnswer1("1. Yellow");
			game[8].setAnswer2("2. Blue");
			game[8].setAnswer3("3. Purple");
			game[8].setAnswer4("4. Red");
			game[8].setCorrect(2);

		game[9].setQuestion("What color is the sky?");
			game[9].setAnswer1("1. Yellow");
			game[9].setAnswer2("2. Blue");
			game[9].setAnswer3("3. Purple");
			game[9].setAnswer4("4. Red");
			game[9].setCorrect(2);

		while(count < 9, count++)
		{
			cout << setw(10) << "Question #" << (count+1) << "." << endl;
			questionAnswer(game, count);
			cout << "Player 1 Answer: ";
			cin >> choice1;
			cout << "Player 2 Answer: ";
			cin >> choice2;

			if(game[count].getCorrect() == choice1)
			{
				points1++;
			}

			if(game[count].getCorrect() == choice2)
			{
				points2++;
			}
		}

		if (points1 > points2)
		{
			cout << "Player 1 WINS!";
		}

		if (points1 < points2)
		{
			cout << "Player 2 WINS!";
		}

		if (points1 == points2)
		{
			cout << "Player 1 and Player 2 are Tied!";
		}
		cout << "\nDo you want to run the program again? Y/N: ";
		cin >> again;

	} while (again == 'y' || again == 'Y');
	return 0;
}

void questionAnswer(questions z[], int count)
{
	cout << z[count].getQuestion() << endl;
	cout << z[count].getAnswer1() << endl;
	cout << z[count].getAnswer2() << endl;
	cout << z[count].getAnswer3() << endl;
	cout << z[count].getAnswer4() << endl;
}


Error List
1 IntelliSense: incomplete type is not allowed c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 8
2 IntelliSense: expected an expression c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 8
3 IntelliSense: expected a ')' c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 8
4 IntelliSense: expected a ';' c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 14
5 IntelliSense: identifier "game" is undefined c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 23
6 IntelliSense: expression must have (pointer-to-) function type c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 96
7 IntelliSense: incomplete type is not allowed c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 134
8 IntelliSense: this declaration has no storage class or type specifier c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 134
9 IntelliSense: expected a ')' c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 134
10 IntelliSense: expected a ';' c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 134
Your first error is usually a good place to start:

1 IntelliSense: incomplete type is not allowed c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 8

This means that there is a problem in line 8 of triviagamedemo.cpp, and the problem is "incomplete type is not allowed". This probably means that you have an incomplete type. "type" refers to data types http://www.cplusplus.com/doc/tutorial/variables/.

Here is line 8 of triviagamedemo.cpp:
void questionAnswer(questions[], int);

Looking at this line I see that questionAnswer returns a type (void), and takes two inputs. One of the inputs is questions[], the other is int. This error is coming from the fact that 'questions' is not a type.

Try repeating this for each of your errors.
Thanks for responding. That fixed a couple of my errors. I'm still getting the following errors...

1 IntelliSense: expected a ';' c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 14
2 IntelliSense: identifier "game" is undefined c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 23
3 IntelliSense: expected a ')' c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 134
4 IntelliSense: identifier "z" is undefined c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 136
5 IntelliSense: identifier "count" is undefined c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 136

Here is the updated code...

Header
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
#ifndef QUESTIONS_H
#define QUESTIONS_H
#include "Questions.h"
#include <string>

class Questions
{
	private:
		string questions;
		string answer1;
		string answer2;
		string answer3;
		string answer4;
		int correctAnswer;

	public:
		void setQuestions(string q)
		{
			questions = q;
		}

		void setAnswer1(string a1)
		{
			answer1 = a1;
		}

		void setAnswer2(string a2)
		{
			answer2 = a2;
		}

		void setAnswer3(string a3)
		{
			answer3 = a3;
		}

		void setAnswer4(string a4)
		{
			answer4 = a4;
		}

		void setCorrectAnswer(int c)
		{
			correctAnswer = c;
		}

		string getQuestions()
		{
			return questions;
		}

		string getAnswer1()
		{
			return answer1;
		}

		string getAnswer2()
		{
			return answer2;
		}

		string getAnswer3()
		{
			return answer3;
		}

		string getAnswer4()
		{
			return answer4;
		}

		int getCorrectAnswer()
		{
			return correctAnswer;
		}
};

#endif 


Main
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
#include <string>
#include <iomanip>
#include "Questions.h"
using namespace std;

char again;
void questionAnswer(string questions[], int);

int main()
{
	do
	{
		string questions game[10];
		int count = 0;
		int choice1, choice2;
		int points1 = 0;
		int points2 = 0;

		cout << "Trivia Game" << endl;
		cout << "-----------" << endl << endl;

		game[0].setQuestion("What color is the sky?");
			game[0].setAnswer1("1. Yellow");
			game[0].setAnswer2("2. Blue");
			game[0].setAnswer3("3. Purple");
			game[0].setAnswer4("4. Red");
			game[0].setCorrect(2);

		game[1].setQuestion("What color is the sky?");
			game[1].setAnswer1("1. Yellow");
			game[1].setAnswer2("2. Blue");
			game[1].setAnswer3("3. Purple");
			game[1].setAnswer4("4. Red");
			game[1].setCorrect(2);

		game[2].setQuestion("What color is the sky?");
			game[2].setAnswer1("1. Yellow");
			game[2].setAnswer2("2. Blue");
			game[2].setAnswer3("3. Purple");
			game[2].setAnswer4("4. Red");
			game[2].setCorrect(2);

		game[3].setQuestion("What color is the sky?");
			game[3].setAnswer1("1. Yellow");
			game[3].setAnswer2("2. Blue");
			game[3].setAnswer3("3. Purple");
			game[3].setAnswer4("4. Red");
			game[3].setCorrect(2);

		game[4].setQuestion("What color is the sky?");
			game[4].setAnswer1("1. Yellow");
			game[4].setAnswer2("2. Blue");
			game[4].setAnswer3("3. Purple");
			game[4].setAnswer4("4. Red");
			game[4].setCorrect(2);

		game[5].setQuestion("What color is the sky?");
			game[5].setAnswer1("1. Yellow");
			game[5].setAnswer2("2. Blue");
			game[5].setAnswer3("3. Purple");
			game[5].setAnswer4("4. Red");
			game[5].setCorrect(2);

		game[6].setQuestion("What color is the sky?");
			game[6].setAnswer1("1. Yellow");
			game[6].setAnswer2("2. Blue");
			game[6].setAnswer3("3. Purple");
			game[6].setAnswer4("4. Red");
			game[6].setCorrect(2);

		game[7].setQuestion("What color is the sky?");
			game[7].setAnswer1("1. Yellow");
			game[7].setAnswer2("2. Blue");
			game[7].setAnswer3("3. Purple");
			game[7].setAnswer4("4. Red");
			game[7].setCorrect(2);

		game[8].setQuestion("What color is the sky?");
			game[8].setAnswer1("1. Yellow");
			game[8].setAnswer2("2. Blue");
			game[8].setAnswer3("3. Purple");
			game[8].setAnswer4("4. Red");
			game[8].setCorrect(2);

		game[9].setQuestion("What color is the sky?");
			game[9].setAnswer1("1. Yellow");
			game[9].setAnswer2("2. Blue");
			game[9].setAnswer3("3. Purple");
			game[9].setAnswer4("4. Red");
			game[9].setCorrect(2);

		while(count < 9, count++)
		{
			cout << setw(10) << "Question #" << (count+1) << "." << endl;
			questionAnswer(game, count);
			cout << "Player 1 Answer: ";
			cin >> choice1;
			cout << "Player 2 Answer: ";
			cin >> choice2;

			if(game[count].getCorrect() == choice1)
			{
				points1++;
			}

			if(game[count].getCorrect() == choice2)
			{
				points2++;
			}
		}

		if (points1 > points2)
		{
			cout << "Player 1 WINS!";
		}

		if (points1 < points2)
		{
			cout << "Player 2 WINS!";
		}

		if (points1 == points2)
		{
			cout << "Player 1 and Player 2 are Tied!";
		}
		cout << "\nDo you want to run the program again? Y/N: ";
		cin >> again;

	} while (again == 'y' || again == 'Y');
	return 0;
}

void questionAnswer(string questions z[], int count)
{
	cout << z[count].getQuestion() << endl;
	cout << z[count].getAnswer1() << endl;
	cout << z[count].getAnswer2() << endl;
	cout << z[count].getAnswer3() << endl;
	cout << z[count].getAnswer4() << endl;
}
Line 14:
string questions game[]
Line 134:
string questions z[]
Whitespace inside a variable name is not permitted as the words will be treated separately. Use commas in this case:
1
2
 string questions, game[] ;
 string questions, string z[]


I believe the other errors you listed are caused from this faux pas.
Last edited on
The problem is the way you are setting up your objects from your Questions class.

string questions game[10];
Here it looks like you are trying to create 10 objects. The compiler is complaining because you have put string in front of your object declaration (the strings are inside your class, you don't need to define anything for the object). So change it to Questions game[10] . Capitalization also needs to be the same as your class.

You are doing a similar thing in your function, you are passing an array of class objects, the string isn't needed.
void questionAnswer(Questions z[], int count)

I also suggest you look into for loops for setting up each of your objects so you don't need to define each one separately like that. I would reread some documents on class objects as you seem slightly confused on how to use them right now http://www.cplusplus.com/doc/tutorial/classes/
Thanks for the help guys. On to the next phase of the program. Still have a couple things to figure out.
Last edited on
Topic archived. No new replies allowed.