c++ - 我在使用数组/函数的 C++ 程序时遇到问题
问题描述
对于我的课程,我需要使用数组而不是包含分数的单个变量来编写程序。为这一章而奋斗。我将在下面留下我的代码。任何帮助将不胜感激。需要找到输入的所有分数之间的总和,减去最高和最低,然后找到平均值。
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
void getJudgeData(double, double);
double calcScore(double);
double findLowest(double);
double findHighest(double);
int main()
{
// Declare variables
const int SIZE = 7;
double scores[SIZE];
double sum;
for (int x = 0; x < SIZE; x++)
double getJudgeData(scores[x]);
return 0;
}
// Function getJudgeData
void getJudgeData(double &judgeScore, double scores[])
{
static int judge = 1;
cout << "Enter score " << judge << ": ";
cin >> judgeScore;
while (judgeScore < 0 || judgeScore > 10)
{
cout << "Invalid score, please enter a score between 0 and 10";
cout << "Enter score " << judge << ": ";
cin >> judgeScore;
}
judge++;
return;
}
// Function calcScore
double calcScore(double scores[])
{
double highest = findHighest(scores);
double lowest = findLowest(scores);
double result = 0;
for (int x = 0; x < 7; x++)
{
result += scores[x];
}
result - findHighest(scores) - findLowest(scores);
cout << fixed << showpoint << setprecision(2);
cout << "The average after the dropping the highest and lowest scores: " << result / 5 << endl;
return result;
}
// Function findLowest
double findLowest(double scores[])
{
double result = 10;
for (int x = 0; x < 7; x++)
{
if (scores[x] < result)
result = scores[x];
}
return result;
}
// Function findHighest
double findHighest(double scores[])
{
double result = 0;
for (int x = 0; x < 7; x++)
{
if (scores[x] > result)
result = scores[x];
}
return result;
}
解决方案
推荐阅读
- javascript - How to pass a javascript return value to spring path variable
- javascript - React Native Hooks:无法在 useEffect 函数的 return() 中显示值
- pandas - 使用 beautifulsoup 将 selenium html 表放入 pandas 数据框
- ios - 如何使用 JSON.serializer 在 Swift 中解析 JSON
- r - R加权抽样程序
- java - 在移动设备上运行 apk 后 python kivy android 应用程序崩溃
- python - 如何将顶点缓冲区数组合并到我的图形程序中?
- python - def __rmul__ -> TypeError: 不能将序列乘以“浮点”类型的非整数
- sed - 如何在某些登录bash后删除部分文本
- algorithm - 具有一个键违规但不影响输入的其余键的二叉树