program that outputs the time it takes for lighg from the sun to reach the planets

Input output program that shows how long the speed of light takes to reach the planet's
Speed of light = 186,283 miles per second
Mercury 36,000,000 miles away
Venus 67,000,000 miles
Earth 93,00,000 miles
Mars 142,000,000 miles
Jupiter 4,840,000,000 miles
Saturn 14,300,000,000
Uranus 179,000,000,000
Neptune 260,000,000,000

60 seconds/min
60 min/hr

Include global constants
n seconds minutes hours

I need help with this please
Okay, what do you need help with? Do you have any code yet? If you show us what work you have done, we can help you (keeping in mind that we help people, not do their work for them).
Well I'm new to class and I have not learned this stuff yet
#include <iostream>
Using namespace std;
Int main () }

I'm confused on where to start I have to prompt user enter the planet which I know is a cout than con but after that I'm not sure how to do this
If you can just help me start it with the first planet I'm sure I can manage the rest off the first one I have the 5th edition c++ programming book to try and look things up for help as well

#include <iostream>
#include <string>
using namespace std;

const double Mecury =36000000;
const double Venus=67000000;
const double Earth=93000000;
const double Mars=142000000;
const double Jupiter= 4840000000;
const double Saturn=14300000000;
const double Uranus=179000000000;
const double Neptune=260000000000;

int main() {

this is what i have soo far anyone can help me ?
Okay, I added a few comments to try and explain what is happening (I ran the program several times, but lumped the output into one bunch):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;

//the constant C is the speed of light
//here I express it in terms of miles per hour
const int C = 670618800;

int main()
{
    string planet; //this will hold the user input
    cout<< "Enter 'Earth' (omit the quotes): "; //prompt the user to enter a planet
    cin>> planet; //get the user input. Note there is a better way to do this with strings
    
    if (planet == "Earth") //check to see if the string in the variable planet is "Earth"
    {   //if it is Earth, find the time (in hours)
        cout<< "It takes light "<< ((double)93000000 / C)<< " hours to travel from the sun to planet "<< planet<< '\n'; 
        //93000000 is the distance (in miles) from the sun to the Earth. You will have to adjust this for each planet.
    }
    
    else if (planet == "Mars")
    {
        cout<< "You now have an example of else if as well \n"; //you will need an else if for each planet
    }
    
    return 0;
}
Enter 'Earth' (omit the quotes): Earth
It takes light 0.138678 hours to travel from the sun to planet Earth

Enter 'Earth' (omit the quotes): Mars
You now have an example of else if as well

Enter 'Earth' (omit the quotes): Neptune


Notice how I entered Neptune, but there was no output? For your program, I might suggest adding an else to inform the user of an invalid entry (I'll leave you to figure this out).

You will also have to adjust the program for the minutes and seconds part.

Does that help any? Please feel free to ask questions about what I have provided.
Last edited on
yes this helps a great deal i know have the layout i can use for each planet now in terms of adjusting it for minutes and seconds do i apply that to the inital program or i have to do all new if statements for both seconds and minutes ?
Do you mean can you put the minutes and seconds in the same block? If so, yes you can:

1
2
3
4
5
6
if (planet == somePlanet)
{
    //print hours calculation
    //print minutes calculation
    //print seconds calculation
}
Topic archived. No new replies allowed.