what am i missing in this i/o file?

coryD's Avatar, Join Date: Mar 2007
Newbie Member
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
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
if (i < 0)
sumNeg += A[i];

This is unnecessary and will never will be executed inside the for loop.
DaWei's Avatar, Join Date: Dec 2006
Team Leader
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.