Asked by sonnysn
I NEED HELP WITH MY CODE!!! it won't compile right
The formula for finding the force of gravity between two objects is Force = grav * (mass1 * mass2) / (radius * radius), where Force = the force of gravity between the two objects, grav = the universal gravitation constant (6.67e-11), mass1 = the mass of the 1st object, mass2 = the mass of the second object, and radius = the distance between the centers of the two objects. Write a C++ program to allow the user to enter mass1, mass2 and the radius. The program should then calculate and display the force of gravity between the objects.
/* Universal Gravitation Program */
#include <iostream.h>
#include <stdlib.h>
int main ( )
{
double grav, mass1, mass2, radius, force;
cout << "Universal Gravitation" << endl;
cout << endl;
cout << "Enter mass1 (kg): ";
cin >> mass1;
cout << endl;
cout << "Enter mass2 (kg): ";
cin >> mass2;
cout << endl;
cout << "Enter radius (meters): ";
cin >> radius;
cout << endl;
grav = (6.67e - 11);
force = grav * (mass1 * mass2) / (radius * radius);
cout.setf(ios::fixed);
cout.precision(2);
cout << "The force of gravity is : " << force << endl;
cout << endl;
cout << endl;
system("Pause");
return (0);
}
The formula for finding the force of gravity between two objects is Force = grav * (mass1 * mass2) / (radius * radius), where Force = the force of gravity between the two objects, grav = the universal gravitation constant (6.67e-11), mass1 = the mass of the 1st object, mass2 = the mass of the second object, and radius = the distance between the centers of the two objects. Write a C++ program to allow the user to enter mass1, mass2 and the radius. The program should then calculate and display the force of gravity between the objects.
/* Universal Gravitation Program */
#include <iostream.h>
#include <stdlib.h>
int main ( )
{
double grav, mass1, mass2, radius, force;
cout << "Universal Gravitation" << endl;
cout << endl;
cout << "Enter mass1 (kg): ";
cin >> mass1;
cout << endl;
cout << "Enter mass2 (kg): ";
cin >> mass2;
cout << endl;
cout << "Enter radius (meters): ";
cin >> radius;
cout << endl;
grav = (6.67e - 11);
force = grav * (mass1 * mass2) / (radius * radius);
cout.setf(ios::fixed);
cout.precision(2);
cout << "The force of gravity is : " << force << endl;
cout << endl;
cout << endl;
system("Pause");
return (0);
}
Answers
There are no human answers yet.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.