Okay, so I have written an exercise using a number of functions to learn array manipulation. I've got the exact output I need and want using cout statements but now I want to dump everything to a "results.dat" file, which I have already created and opened. When running the program, however, when I change a cout << into an outFile <<, I get 'outFile' was not declared in this scope. You can see what I'm shooting for in the OutputTen function where I have tried to dump my array to my file instead of the console. Any ideas? Here's my code:
double Average(int array[])
{
double sum = 0;
double average = 0;
for (int i = 0; i < size; i++)
{
if (array[i] != 0)
sum = sum + array[i];
}
average = sum / (size - 1);
cout << "The average of the values is: " << average << endl;
cout << endl << "-----------------------------------------------------" << endl << endl;
return average;
}
void LargerThanAverage(int array[], double average)
{
int lessThanCount = 0;
int greaterThanCount = 0;
for (int i = 0; i < size - 1; i++)
{
if (array[i] > average)
greaterThanCount++;
if (array[i] < average)
lessThanCount++;
}
cout << greaterThanCount << " values are greater than the average." << endl;
cout << lessThanCount << " values are less than the average." << endl;
for (int i = 0; i < size; i ++)
cout << array[i] << " ";
cout << endl << endl << "-----------------------------------------------------" << endl << endl;
}
void NumOfMultiples(int array[])
{
int counter = 0;
for (int i = 0; i < size; i++)
{
if (array[i] % 4 == 0 && array[i] %7 == 0)
counter++;
}
cout << "There are " << counter << " values that are multiples of both 4 and 7." << endl;
cout << endl << "-----------------------------------------------------" << endl << endl;
}
void LargestValue(int array[])
{
int largest = array[0];
int location = 0;
for (int i = 0; i < size; i++)
{
if (array[i] > largest)
{
largest = array[i];
location = i;
}
}
cout << largest << " is the largest value and it is located at position " << location << " in the array."<< endl;
cout << endl << "-----------------------------------------------------" << endl << endl;
}
void SmallestValue(int array[])
{
int smallest = array[0];
int location = 0;
for (int i = 0; i < size; i++)
{
if (array[i] < smallest)
{
smallest = array[i];
location = i;
}
}
cout << smallest << " is the smallest value and it is located at position " << location << " in the array."<< endl;
cout << endl << "-----------------------------------------------------" << endl << endl;
}