I'm doing a physics exercise to calculate how long it would take a sled to get to the bottom of a hill. I'm getting mostly negative numbers in my output line. For example, if I enter "50" for both hill and slope, I get "It will take you -1 minutes and -17 seconds to get down the hill." What am I doing wrong (and are there better ways to break my answer into minutes and seconds)?
#include <stdio.h>
#include <math.h>
#include <iostream>
usingnamespace std;
//Constant declarations
constdouble GRAVITY_ACCEL = 9.8;
//Function declarations
double getAcceleration ( double angle );
int main () {
double hill, slope, answer;
cout << "What is the length of the hill in meters? ";
cin >> hill;
cout << endl << "What is the slope of the hill? ";
cin >> slope;
answer = hill / getAcceleration( slope );
cout << "It will take you "
<< floor(answer / 60)
<< " minutes and "
<< (int)answer % 60
<< " seconds to get down the hill."
<< endl;
system("PAUSE");
return 0;
}
/*Function definitions
---Acceleration of a sleigh sliding down a hill
is a = g sin a , where a is the slope of the hill,
and the gravity acceleration g = 9.8 meters per second*/
double getAcceleration ( double ang ) {
return sin(ang) * GRAVITY_ACCEL;
}