我在控制台中有此测验程序

我在控制台中有此测验程序

本文介绍了我在控制台中有此测验程序,如何将其放在Win32中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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;
 
}

推荐答案

//#include<iostream.h>
#include<iostream>
using namespace std;



编译并运行.它有效:)
欢呼声,
AR



Compile and run. It works :)
cheers,
AR




这篇关于我在控制台中有此测验程序,如何将其放在Win32中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:09