### Author Topic: Age in other worlds  (Read 4759 times)

#### louiecerv

• Moderator
• User
• Posts: 85
##### Age in other worlds
« on: November 27, 2005, 12:13:05 PM »
PROBLEM:

When you are 18 years old, you are really saying that the earth has circled the sun eighteen times.  Since other planets take less or more days than the earth to travel around the sun, your age will be different in other planets.  You can compute how old you are in other planets by the formula

________x * (365)
_____y = ---------
__________d
where x is the age on earth, y is the age in planet Y, and d is the number of earth days the planet Y takes to travel around the sun.  Write an application the inputs the user's earth age and prints out his/her age on Mercury, Venus, jupiter and Saturn.  The values of d are listed below:

Planet_____number of earth days to orbit the sun
Mercury-----88
Venus-------225
Jupiter------4380
Saturn------10767

SOLUTION

Code: [Select]
`#include <iostream>using namespace std;int main(){ cout << "AGE IN OTHER PLANETS\n\n"; //number of earth days equal to 1 yr of planet int MERCURY=88, VENUS=225, JUPITER=4380, SATURN=10767; int earthAge; float Age; cout << "This program computes the age in " << endl; cout << "other planets when supplied with the age on earth." << endl; //get input cout << "\nAge on earth (years) : "; cin >> earthAge; cout << "\n--- Age in other planets ---\n"; Age = earthAge * 365.0 / MERCURY; cout << "Mercury     :  " << Age << " years" << endl; Age = earthAge * 365.0 / VENUS;     cout << "Venus       :  " << Age << " years" << endl; Age = earthAge * 365.0 / JUPITER; cout << "Jupiter     :  " << Age << " years" << endl; Age = earthAge * 365.0 / SATURN; cout << "Saturn      :  " << Age << " years \n\n";        system("PAUSE");    return 0;}`
Analyze. Design. Develop. Debug. Deploy. Maintain.