问题描述
- 看看我的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;
}
解决方案
multiply一直没有赋值啊
解决方案二:
请问我的代码错在哪?怎么总分和正确率算不了?
解决方案三:
multiply没有计算过,一直是个垃圾值,而且楼主为何不用循环。。。
解决方案四:
你要先计算出multiply的值 然后输入的write值才能比较
解决方案五:
好吧,好吧,我一直没注意到multiply没有算,谢谢大家啦^_^
时间: 2024-10-03 18:14:41