solved  Not getting any output.

joe97038 (2)   Link to this post
this is my homework, but a hint in the right direction would be very helpful.

this program is supposed to take a set of numbers and output the oddcount, sum, and average. also for the even numbers. this is my program so far and it compiles but when the console pops up nothing happens.

so if anyone could point out problems with it, it would be greatly appreciated. thanks

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
//variables
ifstream inData;
double EvenSum;
double EvenCount;
double EvenAverage;
double OddSum;
double OddCount;
double OddAverage;
int Integer;
char Data;
char total;


//get input file
inData.open("Data.txt");
inData >> Integer;

//read numbers from file, determine wether even or odd

while (!inData.eof());

if (Integer%2)
{
total = Integer + OddSum;
OddCount++;

}

else
{
total = Integer + EvenSum;
EvenCount++;
}
//close file
inData.close();

//calculations
OddAverage = OddSum / OddCount;
EvenAverage = EvenSum / EvenCount;

//output. whatcha see...
cout << left << OddAverage << endl;
cout << left <<"----------" << endl;
cout << left << OddSum << endl;
cout << left <<"----------" << endl;
cout << left << OddCount << endl;
cout << left <<"----------" << endl;
cout << left << EvenAverage << endl;
cout << left <<"----------" << endl;
cout << left << EvenSum << endl;
cout << left <<"----------" << endl;
cout << left << EvenCount << endl;

system("pause");
return 0;
}
firedraco (2618)   Link to this post
1.) Your while loop doesn't do anything. I think you meant to put it around where you get the data? As of now it will cause an infinite loop.
2.) OddSum/OddCount and Even don't need to doubles.
joe97038 (2)   Link to this post
oh so i need to give it an exit path i guess. and i made them doubles because some of the numbers in my input file are kinda big. but thanks for the help
firedraco (2618)   Link to this post
If you need bigger numbers, you can use long int instead of int.

Also, int's max is ~2 billion (2,000,000,000).
Last edited on

This topic is archived - New replies not allowed.