#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 Flight {
    double rangeM;
    double flightSeconds;
    double peakM;
};

Flight predict(double speedMps, double angleDeg, double gravityMps2) {
    const double angleRad = angleDeg * std::acos(-1.0) / 180.0;
    const double verticalSpeed = speedMps * std::sin(angleRad);
    const double time = 2.0 * verticalSpeed / gravityMps2;
    return {speedMps * std::cos(angleRad) * time, time,
            verticalSpeed * verticalSpeed / (2.0 * gravityMps2)};
}

int main() {
    double speed = 0.0, gravity = 0.0;
    if (!readNumber("Launch speed (m/s): ", speed, 0.0, 1e4)
        || !readNumber("Gravity magnitude (m/s^2): ", gravity, 1e-6, 1e4)) return 1;
    std::cout << "Ideal model: no drag; launch and landing at equal height.\n"
              << "angle_deg range_m flight_s peak_m\n" << std::fixed << std::setprecision(6);
    for (int angle = 10; angle <= 80; angle += 5) {
        const Flight flight = predict(speed, angle, gravity);
        std::cout << angle << ' ' << flight.rangeM << ' ' << flight.flightSeconds << ' ' << flight.peakM << '\n';
    }
}
