This is an embarassingly easy algorithm, but I seem to have got a mental
block -
Here is a code snippet:
void OffsetToParts(const short midnightOffset, short *hours, short
*minutes, short *seconds)
{
hours = midnightOffset / 3600;
minutes = (midnightOffset / 60) % 60;
seconds = midnightOffset % 60;
}
Now I want to write a function like this :
short PartsToOffset(const short hours, const short minutes, const short
seconds)
{
// ...
}
Any helpers out there ? 4 1573
newbie wrote:
This is an embarassingly easy algorithm, but I seem to have got a mental
block -
Here is a code snippet:
void OffsetToParts(const short midnightOffset, short *hours, short
*minutes, short *seconds)
{
hours = midnightOffset / 3600;
minutes = (midnightOffset / 60) % 60;
seconds = midnightOffset % 60;
}
Now I want to write a function like this :
short PartsToOffset(const short hours, const short minutes, const short
seconds)
{
// ...
}
Any helpers out there ?
This is probably off topic, but you are looking for something like this:
hour * 3600 + minute * 60 + second
Now just translate that into C++ and finish the function PartsToOffset.
F
newbie wrote:
This is an embarassingly easy algorithm, but I seem to have got a mental
block -
Here is a code snippet:
void OffsetToParts(const short midnightOffset, short *hours, short
*minutes, short *seconds)
{
hours = midnightOffset / 3600;
minutes = (midnightOffset / 60) % 60;
seconds = midnightOffset % 60;
}
Any helpers out there ?
I do not know your requirements, but in OffsetToParts function, you are
changing the address of hours, minutes and seconds
anon wrote:
newbie wrote:
>This is an embarassingly easy algorithm, but I seem to have got a mental block -
Here is a code snippet:
void OffsetToParts(const short midnightOffset, short *hours, short *minutes, short *seconds) { hours = midnightOffset / 3600; minutes = (midnightOffset / 60) % 60; seconds = midnightOffset % 60; } Any helpers out there ?
I do not know your requirements, but in OffsetToParts function, you
are changing the address of hours, minutes and seconds
In C++ I'd probably pass each short by reference, not a pointer to it.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
newbie wrote:
This is an embarassingly easy algorithm, but I seem to have got a mental
block -
Here is a code snippet:
void OffsetToParts(const short midnightOffset, short *hours, short
*minutes, short *seconds)
{
hours = midnightOffset / 3600;
minutes = (midnightOffset / 60) % 60;
seconds = midnightOffset % 60;
}
Now I want to write a function like this :
short PartsToOffset(const short hours, const short minutes, const short
seconds)
{
// ...
}
Any helpers out there ?
You are aware that there are 86400 seconds in a day, and that on most
platforms, that won't fit into a short, right? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rob |
last post by:
He ,
I need to generate some random numbers, right now I am using:
Random pk = new Random();
int a = pk.nextInt(540);
and wondering if there is any other methods in java to generate random...
|
by: savesdeday |
last post by:
In my beginnning computer science class we were asked to translate a
simple interest problem. We are expected to write an algorithm that
gets values for the starting account balance B, annual...
|
by: dan |
last post by:
hey peeps,
i am completely new at c++ and i need some help with an
assignment. it is basically about file i/o with fstreams. i
understand how to open a file with fstream, but how would you read,...
|
by: ben |
last post by:
hello,
i'm following an algorithm book and am stuck on an early excersise in
it, not because of the c programming side of it or even the algorithm
side of it, i don't think, but because of maths....
|
by: Bonj |
last post by:
I was in need of an encryption algorithm to the following requirements:
1) Must be capable of encrypting strings to a byte array, and decyrpting
back again to the same string
2) Must have the same...
|
by: karan.shashi |
last post by:
Hey all,
I was asked this question in an interview recently:
Suppose you have the method signature
bool MyPairSum(int array, int sum)
the array has all unique values (no repeats), your...
|
by: nw |
last post by:
Hi,
I previously asked for suggestions on teaching testing in C++. Based
on some of the replies I received I decided that best way to proceed
would be to teach the students how they might write...
|
by: galiorenye |
last post by:
Hi,
Given this code:
A** ppA = new A*;
A *pA = NULL;
for(int i = 0; i < 10; ++i)
{
pA = ppA;
//do something with pA
|
by: copx |
last post by:
Can anyone point me to a simple, fast RRNG function to generate random ints
within a specified range? It is important that each value within the range
has the same probability (uniform...
|
by: almurph |
last post by:
Hi everyone,
Concerning the Needleman-Wunsch algorithm (cf.
http://en.wikipedia.org/wiki/Needleman-Wunsch_algorithm) I have
noticed a possible loop.
Inside the algorithm there is an...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |