Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   what am i missing in this i/o file? (http://www.go4expert.com/forums/i-missing-i-o-file-t3442/)

coryD 16Mar2007 21:28

what am i missing in this i/o file?
 
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;
}


shabbir 16Mar2007 22:20

Re: what am i missing in this i/o file?
 
if (i < 0)
sumNeg += A[i];

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

DaWei 17Mar2007 04:40

Re: what am i missing in this i/o file?
 
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.


All times are GMT +5.5. The time now is 18:53.