So basically, the main is only supposed to have the file input output. but the lowest, highest, sum and average of all numbers all need to be in functions of their own. I read that it's easier to just write the whole code first then split it, but I'm somewhat stumped a bit after doing that. Thanks in adcance
#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
int main()
{
constint ARRAY_SIZE = 12; // Array size.
int numbers[ARRAY_SIZE]; // Array with 12 elements.
int count = 0; // Loop counter variable.
// Get the file name from the user.
cout << "Enter the name of the file you wish to open : ";
string filename; cin >> filename;
// Open the file.
ifstream inputFile(filename.c_str());
// If the file successfully opened, process it.
if (inputFile)
{
while (count < ARRAY_SIZE && inputFile >> numbers[count])
{
count++;
}
// Close the file.
inputFile.close();
}
else
{
// Display an error message.
cout << "Error opening the file.\n\n";
return -1;
}
// Display the numbers read.
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";
// Display the sum of the numbers.
cout << "The sum of these numbers is : ";
int sum = 0; // Initialize accumulator.
for (int count_Sum = 0; count_Sum < ARRAY_SIZE; count_Sum++)
{
sum += numbers[count_Sum];
}
cout << sum << "\n\n";
// Display the average of the numbers.
cout << "The average of these numbers is : ";
double total = 0; // Initialize accumulator.
double average; // To hold the average.
for (int count_Average = 0; count_Average < ARRAY_SIZE; count_Average++)
{
total += numbers[count_Average];
}
average = total / ARRAY_SIZE;
cout << average << "\n\n";
// Display the highest value of the numbers.
cout << "The highest value of these numbers is : ";
int count_Highest;
int highest;
highest = numbers[0];
for (count_Highest = 1; count_Highest < ARRAY_SIZE; count_Highest++)
{
if (numbers[count_Highest] > highest)
{
highest = numbers[count_Highest];
}
}
cout << highest << "\n\n";
// Display the lowest value of the numbers.
cout << "The lowest of these numbers is : ";
int count_Lowest;
int lowest;
lowest = numbers[0];
for (count_Lowest = 1; count_Lowest < ARRAY_SIZE; count_Lowest++)
{
if (numbers[count_Lowest] < lowest)
{
lowest = numbers[count_Lowest];
}
}
cout << lowest << "\n\n";
return 0;
}
yea I have that already. I thought I could just go to where each function would be needed and just created the function there but passing the array there is the issue