#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>

// Read one whole line so a failed conversion cannot trap the input stream.
bool readNumber(const std::string& prompt, double& value, double low, double high) {
    std::string line;
    while (std::cout << prompt && std::getline(std::cin, line)) {
        std::istringstream input(line);
        char extra = '\0';
        if (input >> value && !(input >> extra) && std::isfinite(value)
            && value >= low && value <= high) {
            return true;
        }
        std::cout << "Enter a finite number in [" << low << ", " << high << "].\n";
    }
    std::cerr << "Input ended before a valid number was supplied.\n";
    return false;
}

struct ResistancePair {
    double seriesOhms;
    double parallelOhms;
};

ResistancePair equivalent(double first, double second) {
    // Scaling avoids forming the product first*second.
    const double low = std::min(first, second);
    const double high = std::max(first, second);
    return {first + second, low / (1.0 + low / high)};
}

int main() {
    double first = 0.0, second = 0.0;
    if (!readNumber("First resistance (ohms): ", first, 1e-9, 1e12)
        || !readNumber("Second resistance (ohms): ", second, 1e-9, 1e12)) return 1;
    const ResistancePair result = equivalent(first, second);
    std::cout << std::fixed << std::setprecision(6)
              << "Series (ohms): " << result.seriesOhms << '\n'
              << "Parallel (ohms): " << result.parallelOhms << '\n';
}
