/** * Lunar lander function driver program. Be aware that this does not do much. * All it attempts is a call on each of the specified functions, to ensure they * can produce one correct answer, and that they do not crash. * * @author Kevin O'Gorman */ #include "moonlander.h" #include <math.h> int closeEnough(double a, double b, double epsilon); #define GRAVITY 1.62 int main() { int fuelRate = 0; /* fuel rate in liters per second, 0-9 valid */ int elapsedTime = 0; /* time LM has been piloted in seconds */ int fuel; /* in liters - to be initialized by player */ double acceleration = 0; /* in meters per second per second */ double velocity = 0; /* in meters per second */ double altitude; /* in meters - to be initialized by player */ /* call functions in no particular order */ showWelcome(); fuelRate = getFuelRate(10); fuel = getFuel(); altitude = getAltitude(); /* Now ignore inputs, and use canned values */ altitude = 1; fuel = 2; fuelRate = 3; velocity = -1; acceleration = -1.4; fuel = updateFuel(fuel, fuelRate); velocity = updateVelocity(velocity, acceleration); altitude = updateAltitude(altitude, velocity, acceleration); acceleration = updateAcceleration(GRAVITY, fuelRate); displayLMState(elapsedTime, altitude, velocity, fuel, fuelRate); displayLMLandingStatus(velocity); return 0; } /** * Determine if two given numbers are "close enough" as specified by a third. * @param a The first given number * @param b The second given number * @param epsilon the tolerance allowed for "close enough". * @return 1 if the numbers are "close enough", and 0 otherwise. */ int closeEnough(double a, double b, double epsilon) { return fabs(a - b) < epsilon; }