求好手给讲讲这个程序
求高手给讲讲这个程序;
#include <iostream>
using namespace std;
int main()
{ char key[ ]={'a','c','b','a','d'};
char c;
int ques=0,numques=5,numcorrect=0;
cout<<"Enter the "<<numques<<" question tests:"<<endl;
while(cin.get(c))
{ if(c != '\n')
if(c == key[ques])
{ numcorrect++; cout << " "; }
else cout<<"*";
else
{ cout<<" Score "<<float(numcorrect)/numques*100<<"%";
ques = 0;
numcorrect = 0;
cout << endl;
continue;
}
ques++;
}
}
------解决方案--------------------
cin.get()是类库里的一个函数的,不需要定义,只需要在开头加上#include<iostream>就OK了!
------解决方案--------------------
第一问是这个意思
至于下面的两个else
第一个else如果输入的字符不在key数组中,则输出字符*
第二个else指的是一次输出完毕获取结束'\n'之后,你输入的一串字符中几个正确(与key)数组相吻合,从而算出你正确的分数,通过比率给出~
using namespace std;
int main()
{ char key[ ]={'a','c','b','a','d'};
char c;
int ques=0,numques=5,numcorrect=0;
cout<<"Enter the "<<numques<<" question tests:"<<endl;
while(cin.get(c))
{ if(c != '\n')
if(c == key[ques])
{ numcorrect++; cout << " "; }
else cout<<"*";
else
{ cout<<" Score "<<float(numcorrect)/numques*100<<"%";
ques = 0;
numcorrect = 0;
cout << endl;
continue;
}
ques++;
}
}
------解决方案--------------------
cin.get()是类库里的一个函数的,不需要定义,只需要在开头加上#include<iostream>就OK了!
------解决方案--------------------
第一问是这个意思
至于下面的两个else
第一个else如果输入的字符不在key数组中,则输出字符*
第二个else指的是一次输出完毕获取结束'\n'之后,你输入的一串字符中几个正确(与key)数组相吻合,从而算出你正确的分数,通过比率给出~