/**
 * CPSC490: C/C++ Input/Output example.
 * Igor Naverniouk
 *
 * Problem:
 *     Read a sequence of lines from standard input. Each
 *     line will contain several floating point numbers
 *     separated by spaces. Print to standard output the
 *     sum of the numbers on each line, rounded to 3
 *     decimal places.
 **/

#include <iostream>
#include <stdio.h>
#include <sstream>
using namespace std;

int main()
{
    // Read lines one by one using C++ getline()
    // getline() returns the state of the cin stream
    // after reading, so the loop will stop when the
    // stream reaches the end of file.
    string line;
    while( getline( cin, line ) )
    {
        // Use a string stream to parse the line
        // and add up the numbers
        istringstream in( line );
        double sum = 0.0, x;
        while( in >> x ) sum += x;
		// The >> operator returns the state of the 
		// stream, which is false when the number could
		// not be read.

        // Use printf to output the sum with exactly
        // 3 digits after the decimal point
        printf( "%.3f\n", sum );
    }
    return 0;    // 0 means "program finished normally"
}

/**
 * To compile this file ("io.cpp"), use the command
 * > g++ -Wall io.cpp
 * "-Wall" means "show all warnings".
 * To run it, execute
 * > ./a.out
 * and type in the input. To indicate the end of input,
 * press Ctrl-D. This will close the program's standard
 * input stream. You can also write your input to a
 * file ("io.in") and execute the program like this:
 * > ./a.out < io.in
 **/
