Basic Input/Output Problem

This code refers to a project that I am trying to complete regarding inputs/outputs. The problem reads as follows.

Suppose you have a list of N integers in a file*. You would like to read all the numbers, calculate
the mean (average) of the numbers, and output all these numbers along with their average to another file.

I keep getting an error stating: "invalid operands to binary expression ('std::__1::istream' (aka 'basic_istream<char>') and 'int *')" for line number 44 (I have identified below) of my code. I don't understand why this error keeps occurring as most of the code as written by my professor and deals with topics we have not covered yet. Any help is much appreciated!


#include <iostream>
#include <fstream>
using namespace std;
void readData (istream& is, int* &a, int size);
void printData (ostream& os, int *a, int size, string& name, double ave);
double findAverage(int *a, int size);
int main()
{
ifstream fin;
ofstream fout;
string fileNameI,fileNameO;
cout<<"enter input and output fileNames: ";
cin>>fileNameI>>fileNameO;
fin.open(fileNameI.c_str());
fout.open(fileNameO.c_str());
int size;

fin >> size;
int *a= new int[size];
readData(fin,a,size);
double ave = findAverage(a,size);
printData(cout, a, size, fileNameI, ave);
printData(fout, a, size, fileNameI, ave);

fin.close();
fout.close();
}
void readData (istream& is, int* &a, int size)
{
//ToDo
cin>>size;
cout<<"The number of integers you would like to take the average of = "
<<size;
cin>>a; <- LINE 44
cout<<"The numbers you are averaging are "<<a;
}
double findAverage(int *a, int size)
{
double ave=0;
double sum=0;
//ToDo
for (int i = 0; i < size; i++){
sum = sum + a[i];
}
ave = sum / size;
return ave;

}
void printData (ostream& os, int *a, int size, string& name, double ave)
{
//ToDo
cout<<"The array of integers you used were: "<<*a;
cout<<"The average of this array = "<<ave;
}
Last edited on
Topic archived. No new replies allowed.