Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Questionnaire Type Program in C++ with 3 items of questions. When the user finish answering the 3  items of questions, the program will compute the total number of correct and wrong answer(s). Then, the program will ask if the user want to take the examination again. If the user did not want to take examination again, the program will end/stop with oop loop and arrays


What I have tried:

C++



#include <iostream>
#include <string>
using namespace std;

class Question{
    int answer[3];
    int correct,wrong;
    double a,b,c;
    double sc = 0;
    double wsc = 0;
  
 public:
      int name, age;
    void studentInfo();
    void getAnswerQuestion();
    void displayAnswerQuestionInfo();
};

void Question:: studentInfo(){
    cout<<"Enter your Name: ";
    cin>>name;
   
}

void Question:: getAnswerQuestion(){
    char answer;
     for(int x=0;x<=2;x++){
         cout<<"What is 1 + 1 :";
         cout<<"\na. 2";
         cout<<"\nb. 3";
         cout<<"\nc. 5";
         cin>>answer;
    if (x=='a'||x=='A'){sc=sc+1;}
   else {wsc=wsc+1;}
         
         cout<<"\nWhat is 2 + 1 ? :" ;
         cout<<"\na. 2";
         cout<<"\nb. 3";
         cout<<"\nc. 5";
        cin>>answer;
    if (x=='b'||x=='B'){sc=sc+1;}
   else {wsc=wsc+1;}
   
   
       cout<<". \nWhat is 2 + 4 ?: ";
         cout<<"\na. 2";
         cout<<"\nb. 3";
         cout<<"\nc. 6";
        cin>>answer;
        if (x=='c'||x=='C'){sc=sc+1;}
   else {wsc=wsc+1;}
  
}
}

void Question:: displayAnswerQuestionInfo(){
    
    cout<<"Name: "<<name<<endl;
    cout<<"Age: "<<age<<endl;
    cout<<" "<<endl;
    cout<<"Your Correct score is: "<<+sc<<endl;
    cout<<"Your Incorrect score is : "<<+wsc<<endl;
}


int main(){

    Question qashinfo;
    
    qashinfo.studentInfo();
    qashinfo.getAnswerQuestion();
    qashinfo.displayAnswerQuestionInfo();



Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.
Posted
Updated 31-Oct-21 15:32pm
Comments
Richard MacCutchan 23-Oct-21 8:41am    
You forgot to ask a question.

For one thing, studentInfo never assigns a value to age, so it will probably be a random value when displayAnswerQuestionInfo displays it.
 
Share this answer
 
v2
There's no question, but I'll give you an assumed answer.
With cin the variable "answer" is read in, but then "x" is evaluated.
The for loop doesn't seem to make any sense.

I would put questions and possible answers that the program generates in a field and choose which ones at random.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900