Your physics homework can be a real challenge, and the due date can be really close - feel free to use our assistance and get the desired result.
Be sure that math assignments completed by our experts will be error-free and done according to your instructions specified in the submitted order form.
Our experts will gladly share their knowledge and help you with programming homework. Keep up with the world's newest programming trends.
Get a free quote.
Check the website
for updates.
Receive your completed assignment.
Easy as ABC!
Just provide us with clear instructions and wait for the completed assignment.

Answer on C++ Question for Matt

Question #4841

write a program that ask the user to enter a number of seconds.
There are 60 seconds in a min. if the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds.
There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to 3,600, the program should display the number of hours in that many seconds.
There are 86,400 seconds in a day. If the number entered by the user is greater than or equal to 86,400, the program should display that number of day in that many seconds.

Expert's answer

#include <iostream>
using namespace std;

long InSeconds; // why is this external?

const int HOURS_IN_DAY = 24; // it's good form to make
const int MINUTES_IN_HOUR = 60; // symbolic constants all caps
const int SECONDS_IN_MINUTE = 60;

int seconds; // why are all these external?
int minutes;
int hours;
int days;

int main()
long InMinutes, InHours ;

cout << "This program will turn your seconds into days,"
<< " hours, minutes and seconds." << endl;
cout << "Enter the amount of seconds:__________";
cin >> InSeconds;
Compute seconds, minutes, hours, days in that order.
Trying to do it in reverse order is causing your problem

// compute seconds
seconds = InSeconds % SECONDS_IN_MINUTE ;

// throw away seconds used in previous statement and convert to minutes
InMinutes = InSeconds / SECONDS_IN_MINUTE ;

// compute minutes
minutes = InMinutes % MINUTES_IN_HOUR ;

// throw away minutes used in previous statement and convert to hours
InHours = InMinutes / MINUTES_IN_HOUR ;

// compute hours
hours = InHours % HOURS_IN_DAY ;

// throw away hours used in previous statement and convert to days
days = InHours / HOURS_IN_DAY ;

cout << "That's " ;
if (days > 0)
cout << days << " days " ;
if (hours > 0)
cout << hours << " hours " ;
if (minutes > 0)
cout << minutes << " minutes " ;
if (seconds >0)
cout << seconds << " seconds " ;
cout << endl ;

return 0;


No comments

Leave a comment

Related Questions

Link to us

Share with friends

Get homework help with Assignment Expert:
free questions
Questions and Answers
approved by clients
The service was satisfactory, in that I am placing another order.
However, the fact that I placed the order two weeks prior to it being due and found out after the due date that it would not be delivered was a bit upsetting.
But, the prompt attention of your staff in rectifying that and re-delivering the product with quick turnaround after my e-mail was good customer service.
Hence, I am in the process of placing another order with you.

Mark Lewis on April 2014
solving policy
solving policy
Pay us safely via PayPalPayPal
We deliver professional assignment and homework help for students in USA, UK, Canada, Australia, AE and all over the world.
Terms and Conditions | Privacy Policy | Service
© 2014 BrainRouter LTD. All rights reserved.