gpt4 book ai didi

c - 显示分数以及每个分数获得的次数

转载 作者:行者123 更新时间:2023-11-30 19:42:36 25 4
gpt4 key购买 nike

我的名字是 Adriel,是该网站和编程的新手。无论如何,我的任务需要一些帮助和指导。我将用 C 创建一个程序,允许用户输入最多 5000 个考试成绩。然后给用户 5 个选项,分别是获取平均成绩、从高到低显示所有考试、将考试曲线向上 5 或向下 5 AND 我不能做的就是显示分数以及获得分数的次数。

这是我的代码:

main() {

//Declared variables
char choice;
int i, j, a, n;
int examScore = 0, HIGH = 0, LOW = 0, AVG = 0, count = 0, sum = 0, scoreCount = 0;
int highlow[5000], highExam, lowExam;

do{//Begin do while #1
CLS;
FLUSH;
printf("=========================\n");
printf("===== Score program =====\n");
printf("=========================\n");
printf("A. Exam scores\n");
printf("B. Exams average\n");
printf("C. Exam score High - Low\n");
printf("D. Times scores obtained\n");
printf("E. Curved up 5 pts\n");
printf("F. Curved down 5 pts\n");
printf("Q. Exit program\n");
printf("=========================\n");
printf("Enter your choice: ");
scanf(" %c", &choice);
choice = toupper(choice);
switch (choice){//Begin switch
case 'A':
CLS;
printf("Please Enter The Number of exams:\n");
scanf("%d", &n);

printf("Please Enter %d Numbers\n", n);
for (i = 0; i < n; i++){
scanf("%d", &highlow[i]);
}//end for loop
highlow[examScore];
count++;
sum = sum + examScore;
AVG = sum / count;
highExam = examScore + 5;
lowExam = examScore - 5;
CLS;
for (i = 0; i < n; i++)
{
for (j = i + 1; j<n; ++j)
{
if (highlow[i]<highlow[j])
{
a = highlow[i];
highlow[i] = highlow[j];
highlow[j] = a;
}
}
}


PAUSE;
break;

case 'B':
CLS;
printf("Exam average is: %i\n", AVG);
PAUSE;
break;

case 'C':
CLS;
printf("The numbers arranged in descending order are given below\n");

for (i = 0; i < n; ++i)

{

printf("%i\n", highlow[i]);
}
PAUSE;
break;

case 'D':
CLS;
printf("Amount of times scored was obtained: %i-%i\n", examScore, count);
PAUSE;
break;

case 'E':
CLS;
// printf("Exam scores curved up by 5 pts: %i\n", highExam);
PAUSE;
break;

case 'F':
CLS;
// printf("Exam scores curved down by 5 pts: %i\n", lowExam);
PAUSE;
break;

case 'Q':
CLS;
printf("Quitting program. Goodbye.\n");
PAUSE;
break;

default:
printf("- Invalid entry -\n");
PAUSE;
break;

}//End switch

} while (choice != 'Q');//End do while #1


}//End main

正如你所见,我还远远没有完成,但其他部分对我来说并不是一个大问题。任何帮助和建议将不胜感激。

最佳答案

为什么计算每个分数在 highlow 中出现的次数这么困难?数组?

我正在考虑一种不同的方法,直到我注意到您有一个已排序的分数数组,因此任何重复的分数将彼此相邻。查看 highlow[0] 的值应该很容易。然后将其与 highlow[1] 进行比较看看是否 highlow[0]是重复的。您只需这样做,直到发现下一个不是重复的,然后开始查找下一个数字的重复。

关于c - 显示分数以及每个分数获得的次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460994/

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