大佬帮帮忙这个怎么做?
编写一个控制台程序,完成以下功能:输入若干个职工的年终考核成绩,以负数为结束标志,如果成绩大于100则要求重新输入,直到正确为止;计算一共输入了多少个职工成绩,平均成绩是多少,最高成绩是多少
程序代码:
#if 1 #include <stdio.h> typedef struct worker { float score; }WK; WK wks[100]; void getMes(int &wkNum) { int wkCount = 0; printf("职工考核成绩录入:\n"); do { printf("num %d score : ",wkCount+1); scanf("%f", &(wks[wkCount].score)); while (!getchar()); if (wks[wkCount].score > 100.0) { printf("请输入有效成绩(0-100)\n"); continue; } else if (wks[wkCount].score < 0.0) { wkNum = wkCount; printf("共计录入%d人\t", wkNum); break; } else { ++wkCount; } } while (1); } void get_ave_max(int wknum) { float max = wks[0].score; float ave = 0.0; float total = 0.0; for (int i = 0; i < wknum;++i) { total += wks[i].score; if (max < wks[i].score) { max = wks[i].score; } } ave = total / wknum; printf("ave score : %.3f\tmax score : %.3f\n", ave, max); } int main() { int wkNum; getMes(wkNum); get_ave_max(wkNum); getchar(); } #endif