0

OK, so I have this project to do and cant figure it out. I am not positive on calling functions correctly and I am kind of lost when it comes to parameter passing. So my program needs to read a text file 1 integer at a time, find out if it is odd or even, add 1 to either odd_tally or even_tally, and then display the total # of even and odd integers.

I am only getting 3 Warnings right now and it is for unitialized variables (in_val, odd_tally, even_tally)

```
#include <iostream>
#include <fstream>
using namespace std;
void examine(int, int, int);
void print(int &, int &);
void readFile(ifstream&, int);
int odd(int);
int even(int);
int main()
{
int in_val, odd_tally, even_tally;
ifstream dataIn;
dataIn.open("prj4.txt"); //Open File
if (dataIn.fail()){ //Failure opening file
cout << "Error opening data file.\n";
}
else
{ readFile(dataIn, in_val);
while (!dataIn.eof()) //Loop until end of text file
{
examine(in_val, odd_tally, even_tally); //Call examine function that will determine if integer s odd or even.
print(odd_tally, even_tally); //Call function to display results
}
dataIn.close();
}
return 0;
}
void readFile(ifstream &someFile, int txt_int)
{
while (someFile >> txt_int); //Read File
cout << endl;
}
void examine(int num,int odd,int even)
{
if (num % 2 ==0)
{
int even(even); //Call even function if num is even
}
else
{
int odd(odd); //Call odd function if num is odd
}
}
int odd(int odd_tally)
{
return odd_tally + 1; //Everytime a odd integer is found, add 1 to odd_tally.
}
int even(int even_tally)
{
return even_tally + 1; //Everytime a even integer is found, add 1 to even_tally.
}
void print(int &odd_tally,int &even_tally) //Display the total number of even and odd integers in the file.
{
cout << "There are " << even_tally << " even integers in the file.";
cout << "There are " << odd_tally << " odd integers in the file.";
cout << endl;
}
```

*Edited 7 Years Ago by acdougla17*: n/a