Ok, so now I enter that, and get the input to work like it should - except it only reads in seven numbers, where I want eight, but then on the next run it gives me the following error: Error writing output file. WTF?
I'm just going to put the entire program, because I have NO clue which part of it is going wrong and how the other parts could affect it.
Code:
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
const int MAX_LIST_SIZE = 7;
typedef double list_scores[MAX_LIST_SIZE];
list_scores scores;
void input(double scores[], int length);
void sort(double scores[], int length);
void average_scores(double scores[], int length);
int find_minimum(double scores[], int first, int length );
void swap(double &X, double &Y);
int main()
{ int length = MAX_LIST_SIZE;
input(scores, length);
sort(scores, length);
average_scores(scores, length);
return 0;
}
void sort(double scores[], int length)
{ int min_index = 1;
for (int j = 0; j < length - 1; ++j)
{ min_index = find_minimum(scores, j, length);
if (min_index != j)
swap(scores[j], scores[min_index]);
}
}
void input(double scores[], int length)
{ cout << "Welcome to the judge's auto-scorer!" << endl;
cout << "When prompted, please enter each score." << endl << endl;
for (int lcv = 0; lcv < length; ++lcv)
{ cout << "Please enter score #" << (lcv + 1) << endl;
cin >> scores[lcv];
}
}
void average_scores(double scores[], int length)
{ double sum, average;
scores[0] = 0;
scores[length] = 0;
sum = 0;
for(int m = 0; m < length; ++m)
sum = sum + scores[m];
average = sum / (length - 1);
cout << endl << "The average score given is: " <<
setiosflags(ios::showpoint|ios::fixed) << setprecision(2) << average << endl;
getch();
}
int find_minimum(double scores[], int first, int length)
{ int min_index = first;
for (int k = first + 1; k < length; ++k)
if (scores[k] < scores[min_index])
min_index = k;
return min_index;
}
void swap(double &x, double &y)
{ double temp = x;
x = y;
y = temp;
}
The Error writing output File happens at the end of the code, after the swap function.
Apparently, programs have chosen to hate me as of yesterday...