Compiler shows no errors, then 100+ errors
May 14, 2013 at 3:28am UTC
My compiler gives me no indication that there are errors until the program runs. The list of errors is too long to post.
Here's an example though...
Error 1 error C2146: syntax error : missing ';' before identifier 'questions' c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\questions.h 8
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\questions.h 8
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\questions.h 8
Error 4 error C2146: syntax error : missing ';' before identifier 'answer1' c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\questions.h 9
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\questions.h 9
Here's my 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
#ifndef QUESTIONS_H
#define 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
{
Questions game[10];
int count = 0;
int choice1, choice2;
int points1 = 0;
int points2 = 0;
cout << "Trivia Game" << endl;
cout << "-----------" << endl << endl;
game[0].setQuestions("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].setCorrectAnswer(2);
game[1].setQuestions("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].setCorrectAnswer(2);
game[2].setQuestions("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].setCorrectAnswer(2);
game[3].setQuestions("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].setCorrectAnswer(2);
game[4].setQuestions("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].setCorrectAnswer(2);
game[5].setQuestions("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].setCorrectAnswer(2);
game[6].setQuestions("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].setCorrectAnswer(2);
game[7].setQuestions("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].setCorrectAnswer(2);
game[8].setQuestions("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].setCorrectAnswer(2);
game[9].setQuestions("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].setCorrectAnswer(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].getCorrectAnswer() == choice1)
{
points1++;
}
if (game[count].getCorrectAnswer() == 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 x[], int count)
{
cout << x[count].getQuestions() << endl;
cout << x[count].getAnswer1() << endl;
cout << x[count].getAnswer2() << endl;
cout << x[count].getAnswer3() << endl;
cout << x[count].getAnswer4() << endl << endl;
}
May 14, 2013 at 3:31am UTC
Try including using std::string
in your header file.
May 14, 2013 at 3:38am UTC
I added that and it expected a semicolon after it. With the semicolon, it gives me this...
Error 1 error C2664: 'questionAnswer' : cannot convert parameter 1 from 'Questions [10]' to 'std::string []' c:\users\fred steinman\documents\visual studio 2010\projects\trivia game\trivia game\triviagamedemo.cpp 96
May 14, 2013 at 3:55am UTC
Make sure your function prototype void questionAnswer(string questions[], int );
and your function definition void questionAnswer(Questions x[], int count)
match.
May 14, 2013 at 4:06am UTC
prototype:void questionAnswer(Questions[], int );
definition:void questionAnswer(Questions x[], int count)
like this?
Topic archived. No new replies allowed.