seconds cpp problem I am taking my first programming class and we are using Borland C++ and I am baffled.
Here is what I am supposed to do:
Write a program that inputs seconds and outputs the equivalent in days, hours, minutes and seconds. Example:
This is how the output should look exactly with a box around it.
3032767 seconds = 35 days
2 hours
26 minutes
7 seconds
Note: The result days + hours + minutes + seconds should add up to the number of seconds that were input.
Algorithm
get seconds
Divide seconds by SecondsInDay giving NumberOfDays
Modulus divide seconds by SecondsInDay giving RemainingSeconds
Divide RemainingSeconds by SecondsInHour giving NumberOfHours
Modulus divide RemainingSeconds by SecondsInHour giving RemainingSeconds
Divide RemainingSeconds by SecondsInMinutes giving NumberOfMinutes
Modulus divide RemainingSeconds by SecondsInMinutes giving RemainingSeconds
output NumberOfDays, NumberOfHours, NumberOfMinutes, RemainingSeconds
This is the understanding that I have so far.
// Include Files //////////////////////////////////////////////////////////////
#include <iostream>
#include <conio.h>
#include <math.h>
// Function Prototypes ////////////////////////////////////////////////////////
// Program Mainline ///////////////////////////////////////////////////////////
int main( )
{
const unsigned int SECONDS_IN_DAY;
const unsigned int seconds = 60*60*24;
const unsigned int hours = 60*60;
const unsigned int days = ;
const unsigned int minutes;
//Get input data
cout << "Enter seconds: ";
cin >> seconds;
//The forumla that will be calculated
<< days*24*60*60 + hours*60*60 + mins*60 + secs << endl;
SECONDS_IN_DAY =;
days = seconds / SECONDS_IN_DAY;
hours = 60*60 ;
minutes = minutes % 60;
seconds = seconds - (SECONDS_IN_DAY * days);
//Output results
cout << "SECONDS_IN_DAY"<< seconds << "=" << "days" << days <<endl;
cout << " hours" <<hours<<endl;
cout << " minutes"<<minutes<<endl;
cout << " seconds"<<seconds<<endl;
getch();
return 0;
}//endmn |