// strstr_demo.cpp

#include <cassert>
#include <iostream>
#include <sstream>

using namespace std;

void main()
{
    /************ 1st sample ************/
    // integer value
    const int VALUE = 3;
    int value;

    cout << VALUE << '\n';
    cin >> value;

    assert( value == VALUE );
    cout << "Happy ending!" << '\n';

    /************* 2nd sample ***********
    // double value
    const double VALUE = 3;
    double value;

    cout << VALUE << '\n';
    cin >> value;

    assert( value == VALUE );
    cout << "Happy ending!" << '\n';
    ************************************/

    /******* 3rd sample (WRONG) *********
    // double value with some precision:
    const double PI = 3.1415926;
    double pi;

    cout << PI << '\n'; // fixed-point format: no exponent field
    cin >> pi;

    assert( pi == PI );
    cout << "Happy ending!" << '\n';
    ************************************/

    /******* 4th sample (CORRECT) *******
    // double value with some precision
    const double PI = 3.1415926;
    double pi;
    cout.precision( 7 );
    cin.precision( 7 );

    cout << std::fixed << PI << '\n'; // fixed-point format: no exponent field
    cin >> std::fixed >> pi;

    assert( pi == PI );
    cout << "Happy ending!" << '\n';
    ************************************/

    /*** 5th sample - using string stream ***
    // double value with some precision
    const double PI = 3.1415926;
    double pi;
    stringstream buffer;
    buffer.precision( 7 );

    buffer << std::fixed << PI << '\n'; // fixed-point format: no exponent field
    buffer >> std::fixed >> pi;

    assert( pi == PI );
    cout << "Happy ending!" << '\n';
    ************************************/
}