我不知道我的节目目前有什么问题。我可以得到A,B,D,F的正确值,但是当分数在70到80之间时,它不会返回C值。
我知道我用一种奇怪的方式转到这个项目上,那是因为教授是如何安排作业的。我可以用简单的if语句得到C。我相信这个问题与我的其他(userGrade B)的设置有关。
/* Jon Hays
Assignment 3B Due 9/25/19
"Grade Calculator"
This program calculates the average grade (%)
out of three test scores and converts it to a character
(A, B, C, D, F)*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
double test1;
double test2;
double test3;
char userGrade;
printf("Please input three test scores:");
scanf("%lf %lf %lf", &test1, &test2, &test3);
double testAverage = (test1 + test2 + test3) / 3;
double second3rdAverage = (test2 + test3) / 2;
if (testAverage >= 90)
userGrade = 'A';
else if (testAverage >= 70 && testAverage < 90)
{
if (test3 > 90)
userGrade = 'A';
else
userGrade = 'B';
}
else if (testAverage >= 50 && testAverage < 70)
{
if (second3rdAverage >= 70)
userGrade = 'C';
else
userGrade = 'D';
}
if (testAverage <= 50)
userGrade = 'F';
printf("%c", userGrade);
}发布于 2019-09-24 21:44:56
你的算法是正确的。注释中指示的任务。
如果
。
这意味着,只有当你的总分低于70%时才能获得C级的奖励。我想,你的假设是,手头的任务与真正的评分有关--事实并非如此。
https://stackoverflow.com/questions/58088254
复制相似问题