#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) in the Rezultatai1.txt file. But I only get -2143899376 result.
The problem isn't the huge number, I need the program to give every row's average number separately in the output file, so that in the output file its written (7 ; 9 ; 8)
20as result in the output file.5+8+7=20). How does your input file look like? Btw, integer arithmetic gives(9+9+8)/3=8not9.