#include <iostream>
#include <string>

struct timestamp {
    int hour, min, sec;
};


// overload handles the prepend-0 issue
std::ostream& operator<<( std::ostream& stream, const timestamp& ts ) {
    return stream 
        << (ts.hour < 10 ? "0" : "") << ts.hour << ":"
        << (ts.min < 10 ? "0" : "") << ts.min << ":"
        << (ts.sec < 10 ? "0" : "") << ts.sec;
}

timestamp modify( const timestamp& ts, const std::string& name ) {
    std::cout << name << "'s starting value is: " << ts << "\nWould you like to modify it? [y/n] ";
    std::cout.flush();

    char response;
    std::cin >> response;

    // If no modification; return original
    if( !( response == 'y' || response == 'Y' ) )
        return ts;

    int hour, min, sec;

    hour = min = sec = -1;
    while( hour < 0 || hour > 23 ) {
        std::cout << "Please enter hour [0-23]: ";
        std::cout.flush();
        std::cin >> hour;
    }

    while( min < 0 || min > 59 ) {
        std::cout << "Please enter minutes [0-59]: ";
        std::cout.flush();
        std::cin >> min;
    }

    while( sec < 0 || sec > 59 ) {
        std::cout << "Please enter seconds [0-59]: ";
        std::cout.flush();
        std::cin >> sec;
    }

    return timestamp { hour, min, sec };
}

int main() {
	timestamp t1 { 20, 30, 45 };
    timestamp t2 { 19, 25, 55 };

    t1 = modify( t1, "Time1" );
    t2 = modify( t2, "Time2" );

    std::cout << "Modified:\n" << t1 << "\n" << t2 << std::endl;
}