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

Hello. Im having trouble with this C++ program. Write a program thatasks the user for a filename. Assume the file contains a seriesof numbers, each written on a seperate line. The program should read

#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 #include 4 using namespace std; 6 int getSum (int[], int); 7 int getMin(int[], int); 9 const int NUMBERS= 100; 11 int main ) 12 13 string getFilename; int number[NUMBERS] int sum; int minimum; 15 16 17 18 19 20 cout > getFilename; ifstream file; 23 file.open(getFilename.c str()); 25 for (int 1-0; | > numberlil; 27 28 29 file.close) 31 32 minimum - getMin (number, NUMBERS) cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!