Whats wrong with my code??

Associate
Joined
6 Mar 2009
Posts
495
I am trying to create a quiz in C++ and here is what i have came up with so far:
#include <iostream>

using namespace std;

class Question
{
public:
string question;
string possAnswers;
int marks;
string comment;
int usersAnswer;
int inputAnswer;
int usersScore;

void displayQuestion()
{
cout << endl;
cout << "Question 1" << endl;
cout << "How do you declare a variable x to be a pointer to a constant interger?" << endl;
cout << "1) int * const x" << endl;
cout << "2) int const * const x" << endl;
cout << "3) int const *x" << endl;
cout << "4) int *x" <<endl;
cout << "Please press a number to correspond your answer:" << endl;

}//displayQuestion

void correctAnswer(int usersInput, int usersScore)
{
if(usersInput ==1)
{
usersScore+2;
}

}//correctAnswer
};

void getUsersAnswer(int usersInput)
{
cin >> usersInput;

}//getUsersAnswer


int main()
{

cout << "Welcome to my Quiz on C++. Please press 1-4 to answer each question.";
cout <<endl;

//creating question object
Question q;

//calling displayQuestion function
q.displayQuestion();

//method to get users input
getUsersAnswer(usersInput);

// setting usersScore to zero
q.usersScore=0;

// calling usersScore function
q.correctAnswer(usersInput, usersScore);

system ("pause");
return 0;
}

I am getting errors when calling the usersScore and usersInput functions:(

Can someone give me some guidance please.
 
I had made a typing error in that code that said usersInput instead of usersAnswer, but i changed it and still getting an error saying that the variables are undefined.
 
Thanks for the reply. I understand the way you are setting it out but unfortunately i have been given a set way for how it should be set out but it seems harder to me.

It should have a class Question which should have methods to:

Display the questions
Obtain answers for user
Return the users score
Display comments on there answers

Then there should be another class called Quiz which should:

Present the questions in order
Display the total score.

Its the second class called Quiz that i dont understand because isnt the first class doing the exact same thing??
 
Back
Top Bottom