Help me find tally the numbers of odd and even

So i have this assignment which I don't know too much about it. I just need how to find the oddTally

given the "int.txt" and "out.txt" files, the programmer will read in 20 integers from in.txt, tally the numbers of ood and even number witihn the files, calculate the sum and average of both even and odds numbers respectively and close the program with the following message " thanks for using (first and last name) to do you calculations today". Output all your results within the output file, out. txt, which is given to you as well. follow this prototypes
void readData(int num)
void oodTally(int num)
void oddSum(int num)
void oddAverage(int num)
void evenTally(int num)
void evenSum(int num)
void evenAverage(int num)
void displayNames (string name1, string name 2)

I have so far this

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void readData(int&);
void oddTally(int);
void oddSum(int);
void oddAverage(int);
void evenTally(int);
void evenSum(int);
void evenAverage(int);
void displayNames(string, string);


int main()
{
	int number;
	readData(number);
	system("pause");
	
	return 0;
}

void readData(int &num)
{
	ifstream inputFile;
	
	inputFile.open("in.txt");

	if (inputFile)
	{
		while (inputFile >> num)
		{
			cout << num << endl;
			system("pause");
		}
		inputFile.close();
	}
	else
	{
		cout << "Error reading in.txt ";
	}
}
	
void oddTally(int num)
{
	fstream inputFile;
	int tally = 0;

	while (inputFile >> num)
	{
		if ((num%2)!= 0)
			tally++; 
	}
	
}


in the in.txt the numbers are
25
41
58
96
42
52
63
47
85
96
100
58
99
31
84
94
20
49
87
67
Last edited on
oddTally does not open the file "in.txt"
also the division in oddTally should be % instead of /
% gives the remainder
/ gives the quotient

inside int main you should not be trying to cout a void function
void functions typically are used all by themselves in a single line of code.
so i have to call readData into oddTally?
you need to call inputFile.open
Topic archived. No new replies allowed.