You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

void exe1()//实现用户开始答题
{
int main(void);
void exe2();
int n,m=0,i,tm,t=0,f=0;
char ans[2];
struct test *p1;
system("cls");//清屏
printf("*************************\n");
printf("^_^请输入要答题的个数:");
scanf("%d",&n);
tm=zts(-1);
if(0>n||n>tm)
{
printf("答题数应小于总数!");
exe1();
}
for(i=0;i<n;i++)//n为用户要答题数
{
do
{
m=rand();//置随机数
}while(!(0<m&&m<=tm));//判断产生的随机数是否符合要求
zts(m);
p1=head;//将zts开辟的结构体首地址赋给p1
printf("\n第%d题\n",i+1);
printf("%s\n%s\n%s\n%s\n%s\n 请输入答案:",p1->q,p1->a1,p1->a2,p1->a3,p1->a4);
scanf("%s",&ans);
if(toupper(ans[0])==p1->ture)//判断用户输入的答案是否正确
{
printf("恭喜你答对了!\n\n");
t++;//回答正确统计
}
else
{
printf("对不起,你答错了。。。\n正确答案是:%c\n\n",p1->ture);
f++;//回答错误统计
}
}
p1=head;
do{
head=p1->next;
free(p1);
p1=head;
}while(p1!=NULL);//释放结构体占用内存
printf("*****************************\n");
printf("\n 已完成测试!\n 共做%d道题%d错误%d正确。\n 正确率:%5.2f\n\n",n,f,t,(float)t/n*100);
printf("*****************************\n");
printf("\n\n1.继续答题;2.添加题目;3.返回主菜单;\n请选择:");
i=0;
scanf("%d",&i);
if(i==1)
exe1();//继续答题
else
if(i==2)
exe2();//添加题目
else
main();//返回主菜单
}