我的名字是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
你可能已经看到我还远没有完成,但其他部分对我来说并不是一个大问题。任何帮助和建议都会非常感激。
答案 0 :(得分:0)
为什么计算highlow
数组中每个分数的次数如此困难?
我想到了一种不同的方法,直到我注意到你有一个排序的分数数组,所以任何重复的分数将彼此相邻。应该很容易看到highlow[0]
的值,然后将其与highlow[1]
进行比较,看看highlow[0]
是否重复。你只是这样做,直到你发现下一个不是重复,然后你开始寻找下一个数字的重复。