这个C语言的程序有什么问题呀?会追加分的!

来源:百度知道 编辑:UC知道 时间:2024/05/13 14:09:10
出十道数学题,对的话加分错的话记录错题然后可以REDO~
可是我现在怎么改都只能出来一道题然后就没有反应了...谁能帮帮我啊...
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
void main()
{ FILE *fp; char ch;
int digitid;
int result;
int i,v,w=0,score;
int choice;
int j,k;
int X[10],M[10],N[10],COUNT[10];
int count;

printf("\nPlease input your four digit ID no: ");
scanf("%d",&digitid);

if((fp=fopen("c:\\record.txt","w"))==NULL)
exit(0);
fprintf(fp,"Your previous records are:\r\n");
fclose(fp);

loop:
printf("\n1 Test\n");
printf("2 Check scores\n");
printf("3 Redo the last test\n");
printf("Please make a choice:");
scanf("%d",&choice);

if(choice==1)
{
time_t start=cl

没有

你的x变量有问题,只执行一次啊!
最好多分出一些函数,这样程序结构性强,好维护!
也可以后续调用,
加一个变量统计出题的个数,如果小于10的话继续出题,否则就可以了,最好设置为一个宏常量,可以修改起来很方便.

x的问题,
while (x==100)
{
n=rand()%100;

m=rand()%100;

if (count==0) { x=n+m; if (x>=100) x=100; if (x!=100) printf("\n%d+%d=?\n",n,m);}
else if (count==1) { x=n-m; if (x<=0) x=100; if (x!=100) printf("\n%d-%d=?\n",n,m);}
else if (count==2) { x=n*m; if(x>=100) x=100; if (x!=100)printf("\n%d*%d=?\n",n,m);}
else
{
if(m==0) x=100;
else {y=n%m; if(y==0) x=n/m; else x=100; if (x!=100) printf("\n%d/%d=?\n",n,m);}
}
}
while(x==100)只会执行一遍 ,当第一个题出来之后,x!=100结果for中i调至第二循环时不可能进入while循环出题,所以只会出来一个题

我把程序重新组织了一下,每种选择单独一个函数,修改了一下除法的选择,现在算是可以工作了。 虽然看得出你是刚刚学习编程,还是建议你能直接从面向对象语言开始, Java是个不错得选择

#include <stdlib.h>
#include <stdio.h>
#include <time.h>