C++ Input/output

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int a , b , c , i , n;
    int d = 0;
 ifstream myfile;
 myfile.open("Duomenys1.txt");
 myfile >> n;
 for (int i = 0; i < n; i++ )
 {
     myfile >> a >> b >> c;
     d +=  (a + b + c)/3 ;
 }
ofstream myotherfile;
myotherfile.open ("Rezultatai1.txt");
myotherfile << d;
myotherfile.close();
myotherfile.close();
return 0;
}

The programs should read 3 (3 is n) rows of numbers (5 7 4 ; 9 9 8; 8 7 8), rows are summed up separately and given 3 different averages (7 ; 9 ; 8) and the Rezultatai1.txt file. But I only get -2143899376 result.


Source: c++

Leave a Reply