Guest User

Untitled

a guest
Mar 13th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. // these are now constants.
  8. const float PI = 3.14159265358979323846264338327950288419716939937510; // pi
  9. const float G = 6.673E-11;
  10.  
  11. float orbitalPeriod(float a, float M, float m)
  12. {
  13.     float f = a * 149598E6; // take value for a from user
  14.     return ((sqrt(((4 * PI * PI) / (G * (M + m))) * f * f * f)) / 86400); // perform function
  15. }
  16.  
  17. float orbitalRadius(float T, float M, float m)
  18. {
  19.     float n = T * 86400;
  20.     float d = ((T * T * G * (M + m)) / (4 * PI * PI)); // perform function
  21.     float b = 1 / 3; // give value for b
  22.     return pow(d, b); // raise d to a power of b
  23. }
  24.  
  25. int main() {
  26.     int ans;
  27.     float M, m; // define variables
  28.  
  29.     cout << "please enter value for m" << endl; // prompt user to enter a value for m
  30.     cin >> m; // take value from user
  31.  
  32.     cout << "please enter value for M" << endl; // prompt user to enter value for M
  33.     cin >> M; // take value fromo user
  34.  
  35.     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
  36.     cin >> ans; // take value from user
  37.  
  38.     if (ans == 1) { // Use for loop if User said yes
  39.         float a;
  40.         cout << "What is the orbital radius of the star/planet system in AU?" << endl; // promt user for value for radius
  41.         cin >> a;
  42.         cout << "the orbital period: " << setprecision(5) << orbitalPeriod(a, M, m) << "days" << endl;
  43.     } //else do nothing
  44.  
  45.     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
  46.     cin >> ans; // take value from user
  47.  
  48.     if (ans == 1) { // user for loop if user answered yes to previous question
  49.         float T;
  50.         cout << "What is the orbital period of the star/planet system in days?" << endl; // ask user for value for T
  51.         cin >> T;
  52.         cout << "the orbital radius: " << orbitalRadius(T, M, m) << "AU" << endl;
  53.     } else {
  54.         cout << "There has been an error" << endl;
  55.     }
  56.  
  57. }
Add Comment
Please, Sign In to add comment