This is the code I have so far:
#include<iostream>
using namespace std;
int main()
{
const int min_per_hour = 60;
const int sec_per_min = 60;
const int hours_per_day = 24;
cout << "Input seconds: ";
long int seconds;
cin >> seconds;
cout << seconds << " seconds = " << (seconds/sec_per_min)/(hours_per_day*60) <<
" days, " << << " minutes, " << <<
" seconds." << endl;
cin.get();
cin.get();
return 0;
}
When you read the code you probably noticed a empty space between two operators <<. Between those I want the rest of the "days" field. I want the rest of "days" converted to "minutes" and the rest of the minutes converted to "seconds" as you probably can see. This is probably easy to solve but for some reason I cant manage to do it. I tried using the modulus operator % like this:
(seconds/sec_per_min)%(hours_per_day*60)
To get the rest out of it.
This is an example of output I have followed:
Please enter seconds: 31600000
31600000 seconds = 365 days, 46 minutes, 40 seconds
With my code I get out the 365 days, but the minutes(using modulus operator) is 1066 minutes.
And another thing, please don't discuss better structure in my program, like if you think there are a better way than using constants. The exercise wanted me to use constants and structure my program like this.
Im thankfull for all help I can get.


Sign In
Create Account

Back to top









