Here is my first post. I am looking for a little guidance with my class project. I have all the logic pieces worked out, but I don't know how to import a scores.txt file into an array. For the sake of my testing I just statically entered some data into my array "item". The input file "scores.txt" must have the user enter the file name. The scores.txt file has a different number of entries. I didn't know if I needed to use a 2d array or if I can get by with a single array. I didn't want to go any further without asking first.
Thanks for any and all help I might find here.
I am going to keep working on this in the interim. Thanks again.
My scores.txt file looks like this:
8.2,9.3,8.5,9.5,9.6
7.2,9.3,9.0,9.9,8.5,9.5,9.6
6.2,9.3,9.9,8.5,9.5,9.6
5.2,9.3,9.0,9.9,8.5,9.5,9.6,9.9,9,9
8.2,9.3,9.0,9.9,8.5,9.5,9.6
7.2,9.3,9.0,9.9,8.5,9.5,
6.2,9.3,9.0,9.9,8.5,9.5,8.0,9.6
9.9,9.2,9.3,9.0,9.9,8.5,9.5,9.6,10.0,9.9
#include <iostream>
using namespace std;
int main()
{
double item[10] = {9.2,9.3,9.0,9.9,8.5,9.5,9.6,9.9}; //Declare an array item of ten components
double sum;
int divisor;
int counter;
double max, min, avg, adjavg;
sum = 0;
divisor = 0;
avg = 0;
adjavg = 0;
counter = 0;
max = item[counter];
min = item[counter];
for (counter = 0; counter < 10; counter++)
{
item[counter];
sum = sum + item[counter]; // totals all the numbers
if (item[counter] <= 1)
divisor = counter; // ignores 0 items so avg will calculate
else divisor = divisor++;
if (item[counter] > max) // determines high score so it can be dropped
max = item[counter];
if(item[counter] < min && item[counter] != 0) // determines low score so it can be dropped
min=item[counter];
avg = static_cast<double>(sum/divisor); // calc avg with all non 0 scores
adjavg = static_cast<double>((sum-min-max)/(divisor-2)); // calc avg with high/lo dropped
}
cout << endl;
cout << "The sum of the numbers is: " << sum << endl;
cout << "Divisor =" << divisor << endl;
cout << "The average of the scores is: " << avg << endl;
cout << "The Max number is :" << max << endl;
cout << "The Min number is :" << min << endl;
cout << "The adjusted avg is:" << adjavg << endl;
//cout << "The numbers in reverse order are: ";
//Print the numbers in reverse order
//for (counter = 9; counter >= 0; counter--)
//{
// cout << item[counter] << " ";
// cout << endl;
//}
return 0;
}