// planet.cpp : Defines the entry point for the console application. // // #include "stdafx.h" #include "iostream.h" #include "math.h" #include "string.h" #define MPG 5 //Miles per gallon #define MOE .000001 //Margin of error (how close the float has to be //to an integer to be considered equal) #define PI 3.14159 int main(int argc, char* argv[]) { char token[30]; int radius; //Planet radius int fuel; //Amount of fuel int angle; //Angle of path double fuelNeeded; //Amount of fuel needed to reach crash site cin >> token; while (strcmp(token,"ENDOFINPUT")) { cin >> radius; cin >> fuel; cin >> angle; if (radius < 1 || radius > 100) { cout << "Error: invalid radius -- " << radius << endl; break; } if (fuel < 0 || fuel > 100) { cout << "Error: invalid fuel -- " << fuel << endl; break; } if (angle < 0 || angle > 360) { cout << "Error: invalid angle -- " << angle << endl; break; } //If angle > 180, we want to go around the planet //the other way if (angle > 180) angle = 360 - angle; fuelNeeded = 2 * PI * radius * ((double) angle / 360) * 2 / MPG; if (fuel >= fuelNeeded || (fabs(fuel - fuelNeeded) <= MOE)) cout << "YES " << (int) (fuel - fuelNeeded) << endl; else cout << "NO " << fuel * MPG << endl; cin >> token; cin >> token; } return 0; }