signed in to unsigned int

D

Daz

Please could someone tell me what I need to do, in order to print a
signed int to the screen without it's sign? The original int needs to
be signed so that I can see if it's less than or greater than zero.
Once that's done, and the relevant message it printed to the screen,
the number needs to be printed without its signed.

for example:

You have made $12778
You have lost $-456 (should read you have lost $456).

Thanks in advance.
 
D

Daz

I think I have figured it out.

if the number is a negative:

(total - (total * 2))

May not be the best way, but it appears to work for what I need it for.

I will remove this post shortly.
 
N

Nick Keighley

Daz said:
Please could someone tell me what I need to do, in order to print a
signed int to the screen without it's sign? The original int needs to
be signed so that I can see if it's less than or greater than zero.
Once that's done, and the relevant message it printed to the screen,
the number needs to be printed without its signed.

for example:

You have made $12778
You have lost $-456 (should read you have lost $456).

abs()
 
D

Daz

john said:
How does one remove a post from usenet???

I sit corrected... You can delete only your own posts (through 'Show
options', 'Remove'), as I have done, but I meant to say thread, and
usenet doesn't allow me to delete an entire thread that I started.

Sorry for the wasted space... :eek:)
 
O

osmium

Daz said:
I will remove this post shortly.

In general, you can't do that. It is like unringing a bell. You can go
through the motions, which is an entirely different thing.
 
?

=?ISO-8859-1?Q?Martin_J=F8rgensen?=

Daz said:
I think I have figured it out.

if the number is a negative:

(total - (total * 2))

May not be the best way, but it appears to work for what I need it for.

I will remove this post shortly.

How about:

if(lost_money < 0)
lost_money*(-1);

cout << "You have lost " << lost_money << endl;


Best regards / Med venlig hilsen
Martin Jørgensen
 
D

Daz

osmium wrote:
{
> In general, you can't do that. It is like unringing a bell. You can go
> through the motions, which is an entirely different thing.
}


I agree entirely! It's just a shame that some people may have wasted
time looking at the post when they didn't need to.
I had been thinking about it previously, and the 'post' button seemed
to trigger my brain into creating a solution the moment it was clicked.

This post now looks a complete mess with missing posts. I think single
posts should not be allowed to be removed.

Martin Jørgensen wrote:
{
> How about:
>
> if(lost_money < 0)
> lost_money*(-1);
>
> cout << "You have lost " << lost_money << endl;
}
Nick Keighley wrote:
{
}


Both very good ideas. Thanks gents! :eek:)

Daz
 
D

Daz

Daz wrote:
{
> This post now looks a complete mess with missing posts. I think single
> posts should not be allowed to be removed.
}

I did it again! I meant to say 'thread' not 'post'...
 
R

red floyd

Daz said:
I think I have figured it out.

if the number is a negative:

(total - (total * 2))

May not be the best way, but it appears to work for what I need it for.

I will remove this post shortly.

std::abs()
 
J

Jim Langston

osmium wrote:
{
> In general, you can't do that. It is like unringing a bell. You can go
> through the motions, which is an entirely different thing.
}


I agree entirely! It's just a shame that some people may have wasted
time looking at the post when they didn't need to.
I had been thinking about it previously, and the 'post' button seemed
to trigger my brain into creating a solution the moment it was clicked.

This post now looks a complete mess with missing posts. I think single
posts should not be allowed to be removed.

Martin Jørgensen wrote:
{
> How about:
>
> if(lost_money < 0)
> lost_money*(-1);
>
> cout << "You have lost " << lost_money << endl;
}
Nick Keighley wrote:
{
}


Why not just
std::cout << "You have lost " << -lost_money << std::endl;
 
D

Default User

osmium said:
In general, you can't do that. It is like unringing a bell. You can
go through the motions, which is an entirely different thing.


You can cancel a post, which as the OP was using Google will remove it
from their archives. It's up to individual news servers as to whether
they will honor cancel (or supercede) requests. Some ignore them due to
forged cancels.



Brian.
 
D

Daz

Jim Langston wrote:
{
> Why not just
> std::cout << "You have lost " << -lost_money << std::endl;
}

Fantastic! Althought I didn't even know you could do that with numbers.
:eek:)

Thanks everyone!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top