1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

what am i missing in this i/o file?

Discussion in 'C++' started by coryD, Mar 16, 2007.

  1. coryD

    coryD New Member

    Joined:
    Mar 16, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Mar 16, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    if (i < 0)
    sumNeg += A;

    This is unnecessary and will never will be executed inside the for loop.
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    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.
     

Share This Page