So I have to write a program that
inputs numbers from a single line in a file into an array.
It then uses a function to check which numbers are even or odd, and errors out
negative numbers. The even or odd numbers are then put into an even or odd array.
Then, a second function, finds the highest, lowest, and average of the even and
odd arrays. A third function outputs the higher than average even and odd numbers.
my program so far:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void evenorodd(ifstream& filenumbers, ofstream& outnumbers, ofstream& errorfile, const int inputnumbers[], const int arraymax, int evenarray[], int oddarray[], int& index); // a function to check for and store even and odd numbers into seperate arrays.
int main()
{
ifstream filenumbers;
ofstream outnumbers, errorfile;
const int arraymax = 10;
int index;
const int inputnumbers[arraymax] = {}; //an array to input numbers from a file
int evenarray[arraymax] = {};
int oddarray[arraymax] = {};
void evenorodd(ifstream& filenumbers, ofstream& outnumbers, ofstream& errorfile, const int inputnumbers[], const int arraymax, int evenarray[], int oddarray[], int& index)
{
{
for (int index = 0; index < arraymax; index++)
{
filenumbers >> inputnumbers[index];
if (inputnumbers[index] % 2 == 0)
{
evenarray[index] = inputnumbers[index];
}
else oddarray[index] = inputnumbers[index];
}
}
}
I don't know how to get the function to only read one line of the file (I tried a for loop, didn't work). also, I don't know what to initialize the even and odd arrays to, since I cant really know the exact numbers. im not allowed to use pointers or vectors...
its driving me nuts! ive been working on this for 5 hours!