Code:double baking=.5*(45)+45; double baking_seconds=
In the above example, the top variable would give 67.5 minutes.
How do i write a code such that it'll show 67 mins and 30 seconds?
Thanks
Code:double baking=.5*(45)+45; double baking_seconds=
In the above example, the top variable would give 67.5 minutes.
How do i write a code such that it'll show 67 mins and 30 seconds?
Thanks
Extract the integer and fractional parts.
modf(3) - Linux man page
Or do x - (int)x to get the fraction.
Or do the whole thing as integer seconds, then use /60 and %60 to get minutes and seconds.
Or.....
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Perhaps you can use two ints: seconds and minutes. Do all timing calculations in terms of seconds, and to convert to minutes and seconds, while seconds > 60, subtract 60 and increment minutes.
Read carefully:
And if you have a compiler at your disposal, why not just try it and see what happens?Or do the whole thing as integer seconds, then use /60 and %60 to get minutes and seconds.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
There would be a way to use modulo, though, right?
This is one way:
double baking=67.5
int temp = baking //get the int part of baking
seconds = temp * 3600 //and convert them to seconds
//handle fractional hours to seconds
temp = (baking * 100)*0.6 //calculate seconds from fractional part of baking,
and add them to the seconds from the int part
seconds+=temp; //no fractional part doesn't cause an error
print up seconds