what am i missing in this i/o file?

Newbie Member
16Mar2007,21:28   #1
coryD's Avatar
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
	ifstream in_file;
	
	in_file.open("Summation.dat",ios::in);
	int i;
	int A[20];
	
	float sumPos;
	float sumNeg;
	
	in_file >> i;

	while (!in_file.eof())
	{
	for (i = 0; i < 20; i++)
	{
		if (i < 0)
		sumNeg += A[i];
		
		else sumPos += A[i];
	}
	in_file >> i;
	}
		
	cout << "Sum of Positive Integers = " << sumPos << endl;
	cout << "Sum of Negative integers = " << sumNeg << endl;
	
	in_file.close();
	return 0;
}

Last edited by shabbir; 16Mar2007 at 22:19.. Reason: Code formatting
Go4Expert Founder
16Mar2007,22:20   #2
shabbir's Avatar
if (i < 0)
sumNeg += A[i];

This is unnecessary and will never will be executed inside the for loop.
Team Leader
17Mar2007,04:40   #3
DaWei's Avatar
Furthermore, you have nothing in A[] to work with. You will tend to get better responses if you explain how your code is failing to meet your expectations. You're making us guess, is that nice? Fortunately you have some obvious blunders.