Question
a program that computes a divers score based on the degree of difficulty and 5 judges scores. In diving, the low and the high score
a program that computes a divers score based on the degree of difficulty and 5 judges scores. In diving, the low and the high score are dropped. The middle three scores are added and then multiplied by the degree of difficulty. Unfortunately, this program doesnt work. There are three logical errors in it.
Correct Output (Inputs in Bold)
Please enter the degree of difficulty: 2.3
Please enter the score from Judge #1: 6.0 Please enter the score from Judge #2: 5.5 Please enter the score from Judge #3: 6.5 Please enter the score from Judge #4: 7.0 Please enter the score from Judge #5: 6.0 The score for the dive is: 42.55
*********************************************************************************************************
#include
#include
#include
using namespace std;
// Function Prototypes
void inputData(double[]);
int lowMonth(double[]);
int highMonth(double[]);
double averageSales(double[]);
const char * monthArray[] = { "1:" , "2:" , "3:", "4:", "5:"};
const int NUM_MONTHS = 5;
int main()
{
double salesArray[NUM_MONTHS];
int low, high;
double average;
// Input the monthly sales data
inputData(salesArray);
// Find the month with the highest sales
high = highMonth(salesArray);
// Find the month with the lowest sales
low = lowMonth(salesArray);
// Calculate the average monthly sales
average = averageSales(salesArray);
// Display results
cout << "The score for the dive is: " << setprecision(2) << fixed << average << endl;
cin.get();
cin.get();
}
double difficulty;
// This functions requests the monthly sales data from the user
void inputData(double sales[])
{
cout << "Please enter the degree of difficulty:" << endl;
cin >> difficulty;
for (int i = 0; i < NUM_MONTHS; i++)
{
cout << "Please enter the score from Judge # " << monthArray[i] << " ";
cin >> sales[i];
}
return;
}
// This function determines which month had the highest sales and
// returns the number for that month, 0 = January, 1 = February, etc.
int highMonth(double sales[])
{
double highest = 1;
int highIndex = 1;
for (int i = 0; i < NUM_MONTHS; i++)
{
if (sales[i] > highest)
{
highest = sales[i];
highIndex = i;
}
}
return highIndex;
}
// This function determines which month had the lowest sales and
// returns the number for that month, 0 = January, 1 = February, etc.
int lowMonth(double sales[])
{
double lowest = 999999;
int lowIndex = -1;
for (int i = 0; i < NUM_MONTHS; i++)
{
if (sales[i] < lowest)
{
lowest = sales[i];
lowIndex = i;
}
}
return lowIndex;
}
// This function computes the average monthly sales
double averageSales(double sales[])
{
double sum = 0;
for (int i =0 ; i < NUM_MONTHS; i++)
{
sum += sales[i];
}
return sum * difficulty;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started