my code will read in a file and put the integers in the file into the array. It reads in and displays the integers perfectly, but i am stuck on how to find the factors of each number in the array. when i use my code i get the error: invalid operands to binary.
example:
4, factors = 3
6, factors = 4
#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
const int MAX = 30;
void getfilename(string,string&);
void get_data(ifstream&, double[], int&);
double factor(double[], int);
int main()
{
int n;
double fac;
double list[MAX];
ifstream input;
string filename, file;
getfilename("input",filename);
input.open(filename.c_str());
get_data(input,list,n);
input.close();
fac = factor(list, n);
for (int j=0; j<n; j++)
{
cout << list[j] << right << setw(16) << fac << endl;
}
return 0;
}
double factor(double data[], int n)
{
int facts = 2;
for (int j=0; j<n; j++)
{
if (list[j]%2 == 0)
facts++;
}
return facts;
}
void getfilename(string filetype,string& filename)
{
cout << "Enter name of " << filetype << " file\n";
cin >> filename;
}
void get_data(ifstream& input,double list[],int& n)
{
n=0;
int count = 0;
input >> list[n];
while (!input.eof())
{
n++;
count++;
input >> list[n];
}
}