那我重发:
#include <cstdlib>
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
char *a="hello world. this is a typing game.";
printf("%s",a);
int len= strlen( a );
char *p = new char[ len ];
cout<<"\nNow there were "<<len
<<" words.\nplease input these again:"<<endl;
//scanf("%c",p);
cin.getline(p,len);
//p[len+1]='\0';
int sum=0,err=0;
for(int i=0;i<len;i++)
{
if(p[i]==a[i])
{
sum++;
cout<<"ok "<<p[i]<<" "<<(int)p[i]<<" -- "<<(int)a[i]<<endl;
//system("pause");
}
else
{
err++;
cout<<"the error is "<<(int)p[i]<<" right there "<<(int)a[i]<<endl;
}
}
cout<< sum<<" "<<err<<endl;
double dsum=sum;
double dlen=len;
double r = dsum/dlen;
cout<<"the right percent is "<<r<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}