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
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).
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>
usingnamespace std;
//the constant C is the speed of light
//here I express it in terms of miles per hour
constint 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.
}
elseif (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.
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 ?