I have to Develop a program that determines the number of days, hours, minutes and seconds it took a beacon's signal to travel to the Space Expedition's communication facility. The local receiver that catches the beacon's signal reports the travel time in seconds. Because the station's Executive Office was an English major, he is unable to convert the time from seconds into the required format and needs a program to do it for him.
The program should function as follows:
Ask the user for the time in seconds the signal traveled.
If the time is negative, display an error message to the user and exit.
Compute number of days, hours, minutes and seconds it took a beacon's signal to travel
Display the total travel time in proper units.
This is what I've written, I want someone opinion on how this looks and if there are any changes that I should make. Also, I have to write and "if" statement as the description says. How would I go about doing that? Thanks!
Right, you'll need to add an if statement on line 13 after you read the input to ensure it is nonnegative, as the assignment requests. What don't you understand about if statements? Is it the syntax, or something else?
The rest looks good, except for what I think was a mistake in your reading of the problem. Your program is reporting the total time in different units; e.g., if the user puts in 60 seconds, it will display 60 seconds, 1 minute, 0.016... hours, etc.
I think the intent of the program is to "make change" with the time; instead of reporting it as you have done, an input of 60 seconds was supposed to output "0 days, 0 hours, 1 minute, 0 seconds", or something to that effect.
I'm not entirely sure If I had a mistake or not yet so I will look into it. Also, I'm still new to this and I don't have the 'If' statements all figured out yet. I would do something like this on line 13, for exmaple:
1 2 3 4
if ()
{
cout << " Error please exit the program." << endl;
}
I'm just not sure what to insert in the parenthesis.
You need to put in a boolean expression; i.e., an expression that evaluates to true or false. The expression you want here is actually quite simple, as all you want to do is check if the user's input is nonnegative (i.e., less than zero).