This is my main function for a program with two subfunctions (one to get user input of numbers that need to be averaged and another that averages the numbers):
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void getNumbers (double num, int& count, char yn, ofstream outData);
double averageNumbers (double num1, double sum, double average, int counter, ifstream userData);
int main ()
{
string sentinel;
double number, sum, average;
int counter;
char yn;
ofstream outData;
ifstream userData;
cout << "To continue with the program enter 'continue'. Otherwise enter 'STOP'";
cin >> sentinel;
if (sentinel != "STOP")
{
getNumbers (number, counter, yn, outData);
averageNumbers (number, sum, average, counter, userData);
cout << "The numbers you entered are: " << userData <<endl;
cout << "The average of the numbers is: " << average <<endl;
cout << "To continue with the program enter 'continue'. Otherwise enter 'STOP': ";
cin >> sentinel;
}
return 0;
}
The problem is, my compiler is not letting me use input/output file stream variables as parameters for my functions. It is not 100% necessary that I use functions in this program but I want to impress the teacher and having all these operations enclosed in the function main is like just meeting expectations..not exceeding them like I want to. Is there a way to get around this?