Number Analysis Program

I have to make number analysis program. Write a program that asks the user for a file name. Assume the file contains a series of numbers, each written on a separate line. The program should read the contents of the file into an array and then display the following data:
-The lowest number in the array
-The highest number in the array
-The total of the numbers in the array
-The average of the numbers in the array
Also, the lowest, highest, total, and average should each be obtained by means of an associated user-defined function (getLowest(), getHighest(), etc.).

I did

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

double getTotal(const double[], int);
double getAverage(const double[], int);
double getHighest(const double[], int);
double getLowest(const double[], int);

int main()
{
const int ARRAY_SIZE = 12;
int numbers[ARRAY_SIZE];
int count = 0;
double total,
average,
lowestNumber,
highestNumber;

string filename;
ifstream inputFile;

cout << "Enter the file name: ";
cin >> filename;

inputFile.open(filename);

if (inputFile)
{
while (count < ARRAY_SIZE && inputFile >> numbers[count])
{
count++;
}

inputFile.close();
}

else
{
cout << "Cant open the file.\n\n";
}

int value = count;

cout << "There are " << value << " numbers in the array.\n\n";

cout << "The numbers are: ";

for (int index = 0; index < count; index++)
{
cout << numbers[index] << " ";
}
cout << "\n";

total = getTotal(numbers, ARRAY_SIZE);
cout << "The total is " << total << endl;

average = getAverage(numbers, ARRAY_SIZE);
cout << "The average is " << average << endl;

lowestNumber = getLowest(numbers, ARRAY_SIZE);
cout << "The lowest number is " << lowestNumber << endl;

highestNumber = getHighest(numbers, ARRAY_SIZE);
cout << "The highest number is " << highestNumber << endl;

return 0;
}

double getTotal(const double numbers[], int ARRAY_SIZE)
{
double total = 0;

for (int count = 0; count < ARRAY_SIZE; count++)
total += numbers[count];

return total;
}

double getAverage(const double numbers[], int ARRAY_SIZE)
{
double average = 0;
double total;
total = getTotal(numbers, ARRAY_SIZE);

average = total / ARRAY_SIZE;

return average;
}

double getLowest(const double numbers[], int ARRAY_SIZE)
{
double lowest;

lowest = numbers[0];

for (int count = 1; count < ARRAY_SIZE; count++)
{
if (numbers[count] < lowest)
lowest = numbers[count];
}

return lowest;
}

double getHighest(const double numbers[], int ARRAY_SIZE)
{
double highest;

highest = numbers[0];

for (int count = 1; count < ARRAY_SIZE; count++)
{
if (numbers[count] > highest)
highest = numbers[count];
}

return highest;
}


And I got 5 errors which are
-28 error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)'
-57 error: cannot convert 'int*' to 'const double*' for argument '1' to 'double getTotal(const double*, int)'
-60 error: cannot convert 'int*' to 'const double*' for argument '1' to 'double getAverage(const double*, int)'
-63 error: cannot convert 'int*' to 'const double*' for argument '1' to 'double getLowest(const double*, int)'
-66 error: cannot convert 'int*' to 'const double*' for argument '1' to 'double getHighest(const double*, int)'

How can I fix these errors?
Last edited on
closed account (48T7M4Gy)
Perhaps, int numbers[ARRAY_SIZE]; should be double numbers[ARRAY_SIZE];
Topic archived. No new replies allowed.