变幻无穷的小说:c语言程序修改问题,高手来帮忙!!!!

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 11:43:00
设计一个四则运算出题程序,并显示每道题的回答结果和答案得分及正确答案(每次10题,每题2分)
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define MAXNO 10
#define MAXTIME 1
main()
{ int no; /* 当前已做到第几题 */
int time; /* 该题已做了多少次 */
int x,y,operator; /* 运算数和运算付*/
int answer,guess; /* 标准答案和操作者回答的数 */
int wrong; /* 当前题做错标志 */
int count=0; /* 已做对的题数 */
rand(); /* 随机数发生器初始化 */
for(no=1;no<=MAXNO;no++)
{ printf("NO %d:\n",no);
x=random(1000);
y=random(1000);
operator=random(4);
switch(operator) /* 把0~3转化成+,-,*,/运算付 */
{ case 0:printf("%d+%d=?",x,y);
answer=x+y;
break;
case 1:printf("%d-%d=?",x,y);
answer=x-y;
break;
case 2:printf("%d*%d=?",x,y);
answer=x*y;
break;
case 3:while(y==0||x%y!=0) /* 确保x/y为整数 */
{ x=random(1000);
y=random(1000);
}
printf("%d/%d=?",x,y);
answer=x/y;
}
}
for(time=1;time<=MAXTIME;time++)
{ scanf("%d",&guess);
if(guess==answer)
count++;
printf("%d %d",guess,answer);
}
count=2*count;
printf("%d",count);
}
我写的大致程序如上,现在需要解决的是如何让它在输出小于10个答案的时候也能正确的输出得分,高手来帮帮忙啊!!!!

该了下你的程序,是不是初学者

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

#define MAXNO 10
#define MAXTIME 1
main()
{
int no; /* µ±Ç°ÒÑ×öµ½µÚ¼¸Ìâ */
int times; /* ¸ÃÌâÒÑ×öÁ˶àÉÙ´Î */
int x,y,op; /* ÔËËãÊýºÍÔËË㸶*/
int answer,guess; /* ±ê×¼´ð°¸ºÍ²Ù×÷Õ߻شðµÄÊý */
int count=0; /* ÒÑ×ö¶ÔµÄÌâÊý */
srand( (unsigned)time(NULL) );/* Ëæ»úÊý·¢ÉúÆ÷³õʼ»¯ */
for(no=1;no<=MAXNO;no++)
{
printf("\nQuestion No %d. :",no);
x=1.0 * rand() / RAND_MAX * 1000;
y=1.0 * rand() / RAND_MAX * 1000;
op=1.0 *rand() /RAND_MAX * 4;
switch(op) /* °Ñ0~3ת»¯³É+,-,*,/ÔËË㸶 */
{
case 0:
printf("%d+%d=?",x,y);
answer=x+y;
break;
case 1:
printf("%d-%d=?",x,y);
answer=x-y;
break;
case 2:
printf("%d*%d=?",x,y);
answer=x*y;
break;
case 3:
while(y==0||x%y!=0) /* È·±£x/yΪÕûÊý */
{
x=1.0*rand()/RAND_MAX * 1000;
y=1.0*rand()/RAND_MAX * 1000;
}
printf("%d/%d=?",x,y);
answer=x/y;
}
scanf("%d",&guess);
printf("%d %d",guess,answer);
if(guess==answer)
{
count++;
printf(" Right");
}
else
{
printf(" Wrong");
}
}
printf("\nRight Answer = %d, Wrong Answer = %d\n",count, MAXNO-count);
printf("Your score = %d\n", 100*count/MAXNO);
getch();
}