I cant solve this assignent. I hope a helpfull soul can help me out.

The problems goes like this: Write a program that ask the user to enter the number of seconds as an integer value(use type long) and that then displays the equivalent time in days, hours, minutes and seconds. Use symbolic constants to represent the number of hours in the day, the number of minutes in an hour and the number of seconds in a minute. The output should look like this:

Enter the number of seconds: 31600000
31600000 seconds = 365 days, 46 minutesm 40 seconds

Here is what I have come up with until now, I hope someone really can help me out...

#include <iostream>

using namespace std;

int main(){

int const hourInDay = 24;
int const numOfMinInHour=60;
int const secondsInMin=60;

long second;

cout << "Enter number of seconds: ";
cin >> second;

int days = second / hourInDay / numOfMinInHour / secondsInMin;

cout << days<< "days ";


cin.get();
cin.get();
return 0;
}

First, after entering the number, calculate the number of days.
With what's left after removing the number of days from the number, calculate the number of hours.
Keep going until you get the seconds.

Done that, and doesnt come up with correct result.. I hope someone can help me with making the code?

Then you did it wrong. Are you really asking us to write it for you? We can't help you fix it if we can't see what you did wrong.

Done that, and doesnt come up with correct result.. I hope someone can help me with making the code?

I have the code but won't post it unless you show what you tried.
Come on, just give it a shot.

Ok I have tried now, either I dont understand the assignent or I cant grasp the matematical logical on this assignment... Here is the new code...

#include <iostream>

using namespace std;

int main(){

int const hourInDay = 24;
int const numOfMinInHour=60;
int const secondsInMin=60;

long typedSecond;
cout << "Enter number of seconds: ";
cin >> typedSecond;


int days = typedSecond / hourInDay / numOfMinInHour / secondsInMin;
cout << typedSecond << " seconds = "<< days << " days, ";



int minutes = typedSecond / hourInDay / numOfMinInHour;
cout << minutes << " minutes, ";

int seconds = typedSecond;
cout << seconds << " seconds";
	
cin.get();
cin.get();
return 0;
}

The program converts number of hours into days.
after this, try to code that inputs number of minutes and converts in x days y hours & z minutes.
then u can easily work with seconds.

/*
* Input: Number of Hours 'H'
* Output: 'H' hours = 'X' Days and 'Y' Hours
*/
#include <iostream>
using namespace std ;

void main()
{
	int days, hours ;
	int long inputHours ;
	cout << "Enter Number Of Hours: " ;
	cin >> inputHours ;
	days = 	inputHours / 24 ;		//Quotient(Days)
	hours = inputHours % 24 ;	//Remainder(Hours)
	cout << days << "Days and " << hours << "Hours" << endl ;
	system ("pause");
}
Comments
very helpfull
This question has already been answered. Start a new discussion instead.