-1
數學測驗問你想解決多少問題,並顯示隨機數的加法和減法,然後評分你對問題的回答。我遇到麻煩的事情就是把它打印出來。我需要展示我有多少,我有多少人一起嘗試。示例4出5正確(等級:2/5正確)但即時恢復此例如「等級:2/-1832609951」任何人都可以幫助謝謝!Newbie to C programig:數學測驗成績打印輸出
包括
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;
}
您的變量聲明行是不完整的在這裏..你在TotalWrong之後寫了些什麼? –