P
puzzlecracker
Here is what I have thus far,
class Cell{
public:
const char * GetFormat();
};
char * Formatter (Cell *cell, double value)
{
char formatted[40];
if(value>=0)
sprintf(formatted, cell->GetFormat(), value);
else
// need to figure this out -- the explanation is below.
}
In the formatter function, I need to surround the resulting string
(character array) with parenthesis if the number is negative. What is
the most efficient way to do that? cannot change Cell class nor the
function's interface, and each cell has a different formatting. It's
similar to excel function to display negative values in parenthesis.
Hence if you pass -40 into the Formatter, you should get (20) as a
resulting string.
Thanks
class Cell{
public:
const char * GetFormat();
};
char * Formatter (Cell *cell, double value)
{
char formatted[40];
if(value>=0)
sprintf(formatted, cell->GetFormat(), value);
else
// need to figure this out -- the explanation is below.
}
In the formatter function, I need to surround the resulting string
(character array) with parenthesis if the number is negative. What is
the most efficient way to do that? cannot change Cell class nor the
function's interface, and each cell has a different formatting. It's
similar to excel function to display negative values in parenthesis.
Hence if you pass -40 into the Formatter, you should get (20) as a
resulting string.
Thanks