Click here to Skip to main content
15,918,109 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include<iostream.h>
void scoreQuestion1(char cAnswer);
void scoreQuestion2(char cAnswer);
void scoreQuestion3(char cAnswer);
void scoreQuestion4(char cAnswer);
void scoreQuestion5(char cAnswer);

char arUserAnswers[5];
char arCorrectAnswers[5]={'d','a','d','c','b'};
void recordAnswer(int iQuestion,char cAnswer)
{
  arUserAnswers[iQuestion-1]= cAnswer;
}
void scoreQuiz()
{
  int iTotalCorrect=0;
  for(int ctCount=0;ctCount<5;++ctCount)
  {
      if(arUserAnswers[ctCount]
		  ==arCorrectAnswers[ctCount])
      ++iTotalCorrect;
  }
cout<< "You ANSWERED " 
    << iTotalCorrect  
    << " out of 5 QUESTIONS correctly!"<<endl;
}

void main(){

char cInput;

cout<<"quiz\n";
//question 1
 cout<< "1. Who is the Former Secretary"<< endl
         << " General of  United Nations?"<< endl

 <<"\ta.Mr.George Bush"<<endl
 <<"\tb.Mr.Jimmy Carter"<<endl
 <<"\tc.Mr.Ban Kin Moon"<<endl
 <<"\td.Mr.Kofi Annan"<<endl;
 cout<< "Your answer>";
   cin>>cInput;
   recordAnswer(1,cInput);
  //question 2
 cout<< "2. Where does he come from?"<< endl
 <<"\ta.Ghana"<<endl
 <<"\tb.USA"<<endl
 <<"\tc.Mali"<<endl
 <<"\td.Canada"<<endl;
 cout<< "Your answer>";
   cin>>cInput;
   recordAnswer(2,cInput);
 //question 3
cout<< "3.The Headquaters of the United Nations"<< endl
    << " is situated in which Country"<< endl
 <<"\ta.Tokyo-Japan"<<endl
 <<"\tb.Oslo-Norway"<<endl
 <<"\tc.Accra-Ghana"<<endl
 <<"\td.NewYork-USA"<<endl;
 cout<< "Your answer>";
   cin>>cInput;
   recordAnswer(3,cInput);
 //question 4
   cout<< "4. Who is the current Secretary General"<< endl
       << " of United Nations?"<< endl
 <<"\ta.Ms.Sarah Pollin"<<endl
 <<"\tb.Mr.Botros Botros Ghali"<<endl
 <<"\tc.Mr.Ban Kin Moon"<<endl
 <<"\td.Mr.Kofi Annan"<<endl;
 cout<< "Your answer>";
   cin>>cInput;
   recordAnswer(4,cInput);
    //question 5
cout<< "5. Where does he come from?"<< endl
 <<"\ta.Ghana"<<endl
 <<"\tb.South Korea"<<endl
 <<"\tc.Ireland"<<endl
 <<"\td.Egypt"<<endl;
 cout<< "Your answer>";
   cin>>cInput;
   recordAnswer(5,cInput);
   scoreQuiz();
   cout<<endl;
}

void scoreQuestion1(char cAnswer){
  if(cAnswer=='a')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='b')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='c')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='d')
  cout<<"Correct Answer"<<endl;
 }
 void scoreQuestion2(char cAnswer){
  if(cAnswer=='a')
  cout<<"Correct Answer"<<endl;
  if(cAnswer=='b')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='c')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='d')
  cout<<"Incorrect Answer"<<endl;
 
}

void scoreQuestion3(char cAnswer){
  if(cAnswer=='a')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='b')
  cout<<"Incorrect Answer"<<endl;
    if(cAnswer=='c')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='d')
  cout<<"Correct Answer"<<endl;
 }

void scoreQuestion4(char cAnswer){
  if(cAnswer=='a')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='b')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='c')
  cout<<"Correct Answer"<<endl;
  if(cAnswer=='d')
  cout<<"Incorrect Answer"<<endl;
 }
void scoreQuestion5(char cAnswer){
  if(cAnswer=='a')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='b')
  cout<<"Correct Answer"<<endl;
  if(cAnswer=='c')
  cout<<"Incorrect Answer"<<endl;
  if(cAnswer=='d')
  cout<<"Incorrect Answer"<<endl;
 
}
Posted
Updated 10-Mar-10 4:09am
v2

With VC2008 express create a empty win32 console app.
Add a new cpp file to the project and paste your code into.
Change the first line to:
VB
//#include<iostream.h>
#include<iostream>
using namespace std;


Compile and run. It works :)
cheers,
AR
 
Share this answer
 
What do you mean exactly by "putting it in win32" ? That doesn't mean anything. So please, elaborate on that part.
 
Share this answer
 
You could try to create a dialog application by the VS wizard
and then put the text _T("Welcome") at its title - firstly... :)
 
Share this answer
 
v2
i want to have dialogue box for students name n students id before proceeding to questions to answer
 
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