Question: Hello. Im having trouble with this C++ program. Write a program that asks the user for a filename. Assume the file contains a series of
Hello. Im having trouble with this C++ program.
Write a program that asks the user for a filename. Assume the file contains a series of numbers, each written on a seperate line. The program should read the contents of the file into an array then display the following data:
The lowest number in the array. Highest number in the array. The total of the numbers in the array. The average of the numbers in the array.
Below i included a screenshot of the code and the input file. I also included the code in text. For the getMin function instead of choosing a minimum value I believe its giving a garbage value. The getSum function theres an error at the sum.
Thank You



#include
#include
using namespace std;
int getSum(int[], int);
int getMin(int[], int);
const int NUMBERS = 100;
int main (){
string getFilename;
int number[NUMBERS];
int sum, minimum;
cout
cin >> getFilename;
ifstream file;
file.open(getFilename.c_str());
for (int i = 0; i
file >> number[i];
}
file.close();
minimum = getMin(number, NUMBERS);
cout
sum = getSum(number, NUMBERS);
cout
}
int getSum(int number[], int NUMBERS){
int sum = 0;
for (int i = 0; 0
{
sum = sum + number[i];
}
return sum;
}
int getMin(int number[], int NUMBERS){
int minimum;
minimum = number[0];
for (int i = 1; i
if (number[i]
{
minimum = number[i];
}
}
return minimum;
}
88 ? ? analysis! ? analysiste main.cpp ? main () 1 #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
