【发布时间】:2021-09-16 18:33:23
【问题描述】:
所以我有一个编码项目,我必须计算一个学生在班级中的总成绩,他们有 4 次测验、2 次期中考试和 1 次期末考试。测验和考试权重为 30%,期中考试权重为 40%。我只帮忙做两件事:
- 我的代码不想在没有 4 个单独的输入数字 (79 80 0 0) 的情况下开始。
- 当进入代码的考试部分时,由于某种原因,它会绕过所需的用户输入并将其自动转换为测验编码中的第三个数字。 我正在编写 c 编程。
#include <stdio.h>
int main()
{
int testOne, testTwo;
float totTest, percTest, testPoint;
printf("Enter you test grades:\n");
scanf("%d%d\n",&testOne,&testTwo);
totTest=testOne+testTwo;
printf("Your total grade points is: %.1f\n", totTest);
testPoint=200;
percTest=(totTest*.40)/testPoint *100;
printf("Your percentage is %.1f%\n", percTest);
int quizOne, quizTwo, quizThree, quizFour;
float totQuiz, percQuiz, quizPoint;
printf("Enter you quiz grades:\n");
scanf("%d%d%d%d\n", &quizOne, &quizTwo, &quizThree, &quizFour);
totQuiz=quizOne+quizTwo+quizThree+quizFour;
printf("Your total quiz grade is %.1f\n", totQuiz);
quizPoint=400;
percQuiz=(totQuiz*.30)/quizPoint *100;
printf("Your quiz percentage is %.1f%\n", percQuiz);
int examOne, examPoint; <This is the code that automatically messes up>
float percExam, finGrade;
printf("Enter your exam grade\n");
scanf(" %d\n", &examOne);
examPoint=100;
percExam=(examOne*.30)/examPoint *100;
printf("Your final exam grade is %.1f\n", percExam);
finGrade=(percExam+percQuiz+percTest);
printf("Your overall grade is %.1f%\n", finGrade);
return 0;
}
【问题讨论】:
-
请注意,scanf() 返回已成功处理的输入项的数量。相关:https://stackoverflow.com/questions/10469643/what-does-the-scanf-function-return
-
在互联网上搜索“C 级计算器测验”。以前有人做过,尤其是在 StackOverflow 上。
-
您的代码有一些警告,但似乎有效:https://ideone.com/cnXPuJ 当我为 7 个输入输入 80 时。
-
请选择一个可以帮助其他人解决相同问题的标题,因为 SO 是问题和答案的存储库,而不是个人帮助台。谢谢
标签: c