i have no idea how to do this problem..somebody help?
Write a program that asks the user to enter a number of seconds.
There are 60 seconds in a minute. 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 of seconds entered by the user is
greater than or equal to 86,400, the program should display the number of days
in that many seconds.
i know you are suppose to divide the amount of seconds the user inputs with the seconds that is listed above..but the thing is lets say i input 90 seconds and i divide that with 60..that will give me 1.5. the thing is that 1.5 is suppose to translate to minutes. so in minutes that should be a minute and thirty seconds. how do i do that?
Basically, the calculate function returns the number of decades,years,weeks, etc, if calculable (i.e. enough seconds to make a decade) and the seconds variable is over-written with the remainder by using a pointer and passing the reference of seconds to the calculate function. I set-up some constant variables to represent how many seconds it take to make a minute, hour, etc and used that to pass a divisor to the calculate function.. pretty simple when you know the math.
which would be an easier step than whipping out the calculator and doing it manually.
using this you could easily incorporate centuries if you wanted to
constunsignedint CENTURY = 1*60*60*24*7*52*10*10;
however, you could only calculate one century before going beyond the capabilities of an integer.
I'm really not trying to hijack the thread, but this issue is based on this code I provided and I am stumped.
Out of curiousity, I typed in a letter instead of an integer to see what would happen.
1 2 3 4 5 6 7 8 9 10 11
'testingcode.exe': Loaded 'C:\Users\Lucian\Documents\Visual Studio 2010\Projects\testingcode\Debug\testingcode.exe', Symbols loaded.
'testingcode.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'testingcode.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'testingcode.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'testingcode.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'testingcode.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
The thread 'Win32 Thread' (0x1100) has exited with code -1073741510 (0xc000013a).
'testingcode.exe': Loaded 'C:\Windows\SysWOW64\apphelp.dll', Cannot find or open the PDB file
'testingcode.exe': Loaded 'ImageAtBase0x49f60000', Loading disabled by Include/Exclude setting.
'testingcode.exe': Unloaded 'ImageAtBase0x49f60000'
The program '[1072] testingcode.exe: Native' has exited with code -1073741510 (0xc000013a).
It threw this up. I tried wrapping the assignment to seconds through cin with try/catch, nothing. So I wrapped the contents of the CALCULATE function with try/catch, nothing.
EDIT: SIGH, n/m. I walked away in frustration and it came to me.
when i put for example 90 as an put it only outputs 30 cause im using the % so it only displays the remainder...i want it to display the whole thing the integer and the remainder ( 1:30 ) a minute and thirty seconds
#include<iostream>
usingnamespace std;
int main()
{
int d,h,m,s,n; long t,r; char ch='y';
while(ch=='y'||ch=='Y')
{
cout<<"Menu:\n1.Convert total time to seconds.\n2.Convert the given time in seconds to standard notation.";
cout<<"\nEnter your choice:";
cin>>n;
switch(n)
{
case 1:
cout<<"\nPlease enter the no. of days:";
cin>>d;
cout<<"\nPlease enter the no. of hours:";
cin>>h;
cout<<"\nPlease enter the no. of minutes:";
cin>>m;
cout<<"\nPlease enter the no. of seconds:";
cin>>s;
t=86400*d+3600*h+60*m+s;
cout<<"\nThe total time in seconds is:\n";
cout<<t<<"secs";
break;
case 2:
cout<<"Please enter the time in seconds:";
cin>>t;
if(t>=86400)
{
d=t/86400;
cout<<d<<"days ";
}
r=t%86400;
if(r>=3600)
{
h=r/3600;
cout<<h<<"hours ";
}
r%=3600;
if(r>=60)
{
m=r/60;
cout<<m<<"mins ";
}
s=r%60;
if(s>0)
cout<<s<<"secs ";
}
cout<<"\nWant to try again?\nPress y to try again.\nPress any other key to terminate.";
cin>>ch;
}
return 0;
}