gpt4 book ai didi

c - C 编程新手 : Math Quiz grade printout

转载 作者:行者123 更新时间:2023-11-30 20:22:45 28 4
gpt4 key购买 nike

数学测验询问您想要解决多少个问题,并显示加法和减法的随机数,然后对您对问题的回答进行评分。我遇到的问题是正确打印它。我需要显示我做对了多少个以及我总共尝试了多少个。示例 5 分中的 4 分正确(成绩: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;
}

最佳答案

我再次查看了问题,找到了我应该针对“错误数量/总数”执行此操作的解决方案

TotalCorrect = AddCorrect + SubCorrect;
printf("\n");
printf("Grade: %d/%d\n",TotalCorrect,NumberOfTimes);
printf("\n");
return 0;

关于c - C 编程新手 : Math Quiz grade printout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38734375/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com