2 gudong1996 gudong1996 于 2016.04.09 13:02 提问

看看我的c语言代码存在哪?为啥计数器用不了?

要求:电脑连续出十道乘法题,算对一道十分,最后输出正确率和总得分。 #include
#include
#include
int main()
{
int ret,magic,multiply;//ret,magic分别为计算机产生的1~10之间的随机数,multiply为它们的乘积
int write;
int counter=0;
int score,percent;//score为分数,percent为正确率
//====================1
srand(1);
ret=rand()%10+1;
magic=rand()%10+1;
printf("%d*%d=?\n",magic,ret);
scanf("%d",&write);
if(write==multiply) counter++;
//==================2
srand(2);
ret=rand()%10+1;
magic=rand()%10+1;
printf("%d*%d=?\n",magic,ret);
scanf("%d",&write);
if(write==multiply) counter++;
//======================3
srand(3);
ret=rand()%10+1;
magic=rand()%10+1;
printf("%d*%d=?\n",magic,ret);
scanf("%d",&write);
if(write==multiply) counter++;

//====================4
srand(4);
ret=rand()%10+1;
magic=rand()%10+1;
printf("%d*%d=?\n",magic,ret);
scanf("%d",&write);
if(write==multiply) counter++;
//====================5
srand(5);
ret=rand()%10+1;
magic=rand()%10+1;
printf("%d*%d=?\n",magic,ret);
scanf("%d",&write);
if(write==multiply) counter++;
//===============6
srand(6);
ret=rand()%10+1;
magic=rand()%10+1;
printf("%d*%d=?\n",magic,ret);
scanf("%d",&write);
if(write==multiply) counter++;
//=================7
srand(7);
ret=rand()%10+1;
magic=rand()%10+1;
printf("%d*%d=?\n",magic,ret);
scanf("%d",&write);
if(write==multiply) counter++;
//=====================8
srand(8);
ret=rand()%10+1;
magic=rand()%10+1;
printf("%d*%d=?\n",magic,ret);
scanf("%d",&write);
if(write==multiply) counter++;
//==================9
srand(9);
ret=rand()%10+1;
magic=rand()%10+1;
printf("%d*%d=?\n",magic,ret);
scanf("%d",&write);
if(write==multiply) counter++;
//===============10
srand(10);
ret=rand()%10+1;
magic=rand()%10+1;
printf("%d*%d=?\n",magic,ret);
scanf("%d",&write);
if(write==multiply) counter++;
score=counter*10;
percent=counter/10*100;
printf("总分为%d,正确率为%d%%",score,percent);
 return 0;

}

5个回答

niu911756178
niu911756178   2016.04.09 13:43
已采纳

multiply一直没有赋值啊

gudong1996
gudong1996   2016.04.09 13:05

请问我的代码错在哪?怎么总分和正确率算不了?

qq423399099
qq423399099   Ds   Rxr 2016.04.09 13:53

multiply没有计算过,一直是个垃圾值,而且楼主为何不用循环。。。

g_base
g_base   2016.04.09 14:53

你要先计算出multiply的值 然后输入的write值才能比较

gudong1996
gudong1996   2016.04.09 16:28

好吧,好吧,我一直没注意到multiply没有算,谢谢大家啦^_^

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!