Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- // these are now constants.
- const float PI = 3.14159265358979323846264338327950288419716939937510; // pi
- const float G = 6.673E-11;
- float orbitalPeriod(float a, float M, float m)
- {
- float f = a * 149598E6; // take value for a from user
- return ((sqrt(((4 * PI * PI) / (G * (M + m))) * f * f * f)) / 86400); // perform function
- }
- float orbitalRadius(float T, float M, float m)
- {
- float n = T * 86400;
- float d = ((T * T * G * (M + m)) / (4 * PI * PI)); // perform function
- float b = 1 / 3; // give value for b
- return pow(d, b); // raise d to a power of b
- }
- int main() {
- int ans;
- float M, m; // define variables
- cout << "please enter value for m" << endl; // prompt user to enter a value for m
- cin >> m; // take value from user
- cout << "please enter value for M" << endl; // prompt user to enter value for M
- cin >> M; // take value fromo user
- cout << "Would you like to find the orbital period? Enter 1 for yes, enter any other value for no." << endl; // ask user if he would like to find the orbital period
- cin >> ans; // take value from user
- if (ans == 1) { // Use for loop if User said yes
- float a;
- cout << "What is the orbital radius of the star/planet system in AU?" << endl; // promt user for value for radius
- cin >> a;
- cout << "the orbital period: " << setprecision(5) << orbitalPeriod(a, M, m) << "days" << endl;
- } //else do nothing
- cout << "Would you like to find the orbital radius? Enter 1 for yes, enter any other value for no" << endl; // ask user if he'd like to enter the orbital radius
- cin >> ans; // take value from user
- if (ans == 1) { // user for loop if user answered yes to previous question
- float T;
- cout << "What is the orbital period of the star/planet system in days?" << endl; // ask user for value for T
- cin >> T;
- cout << "the orbital radius: " << orbitalRadius(T, M, m) << "AU" << endl;
- } else {
- cout << "There has been an error" << endl;
- }
- }
Add Comment
Please, Sign In to add comment