我在控制台中有此测验程序,如何将其放在Win32中 [英] i have this quiz program in console,how can i put it in Win32
本文介绍了我在控制台中有此测验程序,如何将其放在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;
}
推荐答案
使用VC2008 Express创建一个空的win32控制台应用程序. 将新的cpp文件添加到项目中,然后将代码粘贴到其中.
将第一行更改为:
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:
//#include<iostream.h>
#include<iostream>
using namespace std;
编译并运行.它有效:)
欢呼声,
AR
Compile and run. It works :)
cheers,
AR
将其放入win32"到底是什么意思?那没什么意思.因此,请对此部分进行详细说明.
What do you mean exactly by "putting it in win32" ? That doesn''t mean anything. So please, elaborate on that part.
您可以尝试通过VS向导创建对话框应用程序
然后将文本_T("Welcome")
放在标题上-首先...:)
You could try to create a dialog application by the VS wizard
and then put the text_T("Welcome")
at its title - firstly... :)
这篇关于我在控制台中有此测验程序,如何将其放在Win32中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文