数学测验询问您要解决的问题数量,并显示随机数的加法和减法,然后对问题的响应进行评分。我遇到麻烦的事情就是将它打印出来。我需要显示我有多少权利和多少我一起尝试过。示例4中有5个正确(等级:2/5正确)但我正在恢复这个例如“等级:2 / -1832609951 ”任何人都可以帮助谢谢!
int main()
{
int NumberOfTimes,AddAns,SubAns,AddCorrect=0,SubCorrect=0,CorrectAnsAdd,CorrectAnsSub,TotalCorrect,TotalWrong,Add$
int i,a,b,c,d,e,f,g;
printf("\n");
printf("-------------------MATH QUIZ------------------------\n");
printf("Enter the number of Math problems you want to solve:");
scanf("%d", &NumberOfTimes);
printf("\n");
srand(time(NULL));
for (i=0;i<NumberOfTimes;++i)
{
b = rand() %3 + 1;
c = rand() %3 + 1;
a = rand() %2 + 1;
if (a == 1)
{
printf("%d + %d = ", b,c);
scanf("%d", &AddAns);
d = b + c;
if (AddAns == d)
{
printf(" +Correct\n");
AddCorrect = AddCorrect + 1;
}
else
{
printf(" +Wrong, it was %d\n", d);
AddIncorrect = AddIncorrect + 1;
}
}
if (a == 2)
{
printf("%d - %d = ", b,c);
scanf("%d", &SubAns);
g = b - c;
if (SubAns == g)
{
printf(" +Correct\n");
SubCorrect = SubCorrect + 1;
}
else
{
printf(" +Wrong, it was %d\n", g);
SubIncorrect = SubIncorrect + 1;
}
}
}
TotalCorrect = AddCorrect + SubCorrect;
TotalWrong = AddIncorrect + SubIncorrect;
printf("\n");
printf("Grade: %d/%d\n",TotalCorrect,TotalWrong);
printf("\n");
return 0;
}
答案 0 :(得分:1)
我再次看了一下这个问题并找到了解决方案我应该为#34;错误数量/总数&#34;
TotalCorrect = AddCorrect + SubCorrect;
printf("\n");
printf("Grade: %d/%d\n",TotalCorrect,NumberOfTimes);
printf("\n");
return 0;