Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- int round2(double d){
- if ( d - (int)d >=0.5){
- return (int)d + 1;
- }
- else{
- return (int)d;
- }
- }
- int main()
- {
- int r,g,b;
- fstream plik( "swiatla.txt", ios::in );
- if( plik.good() )
- {
- string napis;
- //cout << "Zawartosc pliku:" << endl;
- int n; //liczba zestawawow danych
- plik >> n;
- while( !plik.eof() )
- {
- int sumR, sumG, sumB;
- double avgR, avgG, avgB;
- sumR =sumG = sumB=0;
- avgR = avgG = avgB = 0;
- for (int i=0; i<10; i++){
- //getline( plik, napis );
- plik >> r;
- plik >> g;
- plik >> b;
- sumR += r;
- sumG += g;
- sumB += b;
- }
- avgR = sumR/10.0;
- avgG= sumG/10.0;
- avgB = sumB/10.0;
- //int avgRint = (int) avgR;
- // double d = 5.9; (int)d = 5 -> 5.9 - 5 = 0.9 > 0.5
- // double d = 5.4; (int)d = 5 -> 5.4 - 5 = 0.4
- //cout << avgR << " " << round2(avgR) << " " << " " << avgG << " " << avgB << endl;
- cout << round2(avgR) << " " << round2(avgG) << " " <<round2(avgB) << endl;
- }
- }
- plik.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement