gpt4 book ai didi

C 分级程序 : Not Returning 'C' for Grading Program

转载 作者:太空宇宙 更新时间:2023-11-04 07:44:43 28 4
gpt4 key购买 nike

目前我不确定我的程序出了什么问题。我可以获得 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);
}

最佳答案

您的算法是正确的。您在评论中指出的任务

  • If the average score is 90% or more, the grade is A.
  • If the average score is 70% or more and less than 90%, check the third score.
    • If the third score is more than 90%, the grade is A; otherwise the grade is B.
  • If the average score is 50% or more and less than 70%, check the average of the second and third scores.
    • If the average of the two is greater than 70%, the grade is C; otherwise the grade is D.
  • If the average score is less than 50% then the grade is F.

表示,只有当您的总分低于 ​​70% 时才会获得 C。我想,您的假设是手头的任务与实际评分有关 - 但事实并非如此。

关于C 分级程序 : Not Returning 'C' for Grading Program,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58088254/

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