回复 楼主 a17080
#include<stdio.h>
#include<windows.h>
#include <stdlib.h>
void gotoxy(int x,int y);
double jiafa(void);
char mygetchar(void);//清空输入
int main(void)
{
int i;
double pa;
printf("选择练习项目:\n");
printf("1.练习加法 2.练习减法\n");
printf("3.练习乘法 4.练习除法\n");
printf("5.退出系统\n");
while(i=mygetchar())
{
if(i>'0'&&i<'6')
break;
printf("输入错误!请重新输入:");
}
switch(i)
{
case '1' : system("cls");pa=jiafa();break;
case '5' : break;
}
printf("您的正确率为:%.2lf%%",pa*100);
getchar();//为什么加这个
return 0;
}
double jiafa(void)
{
int a[5],b[5],i,m=0,n=0,x,y=0;
double p;
char ch,ch2;
srand((unsigned)time(NULL));//随机数
do
{ system("cls");
printf("选择范围:\n");
printf("a.0-10 b.0-20\n");
printf("c.0-50 d.0-100\n");
ch=mygetchar();
while(ch<'a'||ch>'d')
{
printf("输入错误!请重新输入:");
y++;
ch=mygetchar();
}
if(ch=='a')
{
for(i=0;i<5;++i)
{
a[i]=rand()%11;
b[i]=rand()%11;
printf("%2d+%2d=\n",a[i],b[i]);
}
}
if(ch=='b')
{
for(i=0;i<5;++i)
{
a[i]=rand()%21;
b[i]=rand()%21;
printf("%2d+%2d=\n",a[i],b[i]);
}
}
if(ch=='c')
{
for(i=0;i<5;++i)
{
a[i]=rand()%51;
b[i]=rand()%51;
printf("%2d+%2d=\n",a[i],b[i]);
}
}
if(ch=='d')
{
for(i=0;i<5;++i)
{
a[i]=rand()%101;
b[i]=rand()%101;
printf("%2d+%2d=\n",a[i],b[i]);
}
}
for(i=0;i<5;++i)
{
m++;
gotoxy(7,i+y+4);
scanf("%d",&x);
if(x==a[i]+b[i])
{
gotoxy(15,i+y+4);
printf("√");
n++;
}
else
{
gotoxy(15,i+y+4);
printf("×");
}
}
while(getchar()!='\n')
continue;
printf("\n是否继续?(Y/N)\n");
ch2=mygetchar();
}while(ch2!='N'&&ch2!='n');
system("cls");
p=(1.0*n)/m;
gotoxy(26,12);
return p;
}
void gotoxy(int x, int y)//移动光标
{
COORD coord = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
char mygetchar(void)
{
char ch;
ch=getchar();
while(getchar()!='\n')
continue;
return ch;
}