输入五题的答案,与正确答案作比较,正确输出为“ ”,错误输出为“*”并统计正确率,直到输入ctr+z结束程序
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const char key[]={'a','d','b','b','c'};
const int Num=5;
char c;
int i=0;
int correctNum=0;
while (cin.get(c))
{
if (c!='\n')
{
if (c==key[i])
{
correctNum++;
cout<<" ";
}
else
{
cout<<"*";
}
i++;
}
else
{
cout<<"Score"<<100*(float)correctNum/Num<<"%"<<endl;
correctNum=0;
i=0;
}
}
system("Pause");
return 0;
}