- #1
elly_55
Homework Statement
[/B]
Write a function fForceOfGravity, with return type double and with two double parameters for mass (m) and gravity (g). Parameter gravity must be initialized to 9.81. The force of gravity is given by the formula F=mg. Call these functions in the main () as follows:
cout << fForceOfGravity (75); //75 kg on Earth
cout << fForceOfGravity (75, 1.62); //75 kg on the Moon
Homework Equations
F = mg
knowledge of :
calling by reference
overloading
default arguments
The Attempt at a Solution
[/B]
Hi, I am a novice programmer trying to write a function to calculate the force of gravity on an object using a function that incorporates the concepts of calling by reference, overloading, and default arguments. I would like this function to execute from the main when called upon with specific entered values, and would like to rid my function of the output and input values required within the function. This is what I have so far, how can I move forward to achieve my goal? Thank you in advance :) !
C:
double fForceOfGravity(double & mass, double & gravity = 9.81);
{
double y, F, temp;
cout << "please enter the object's mass in kilograms: " << endl;
cin >> mass >> endl;
cout << "would you like to calculate the force of gravity on Earth (yes or no)? " << endl;
cin >> answer >> endl;
if answer == 'yes'
{
F = mass * gravity
}
else
{
cout << "please enter the acceleration due to gravity in m/s^2 :" << endl;
cin >> y >> endl;
temp = gravity;
gravity = y;
y = gravity;
F = mass * gravity;
}
return F