计算学生等级:针对每门课程,根据学生的积分,计算相应等级。

img


以下是我的算法

#include 
#include 
int main()
{
    double level;
    double score;
    printf("输入分数:");
    scanf("%lf",&score);
    level=log10(score+1);
    printf("等级为:%.0lf",level);
    return 0;
}

由于计算机设定的规定(四舍五入)对等级不知道怎么计算
以下是我的算法的运行结果:

img

img

img

img


在分数为1,2是不符合等级计算法则
应该怎么修改?

#include <stdio.h>
#include <math.h>

int get_grade(int score) {
  // If the score is between 1 and 8, the grade will be 1
  if (score >= 1 && score <= 8) {
    return 1;
  }

  // Otherwise, calculate the grade using the formula:
  // grade = [log10(score + 1)]
  return (int)log10(score + 1);
}

int main() {
  // Prompt the user for a score
  printf("Enter a score: ");
  int score;
  scanf("%d", &score);

  // Calculate the grade
  int grade = get_grade(score);

  // Print the result
  printf("Grade: %d\n", grade);

  return 0;
}

这次可以了,我都运行试过了,望采纳