Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > signed in to unsigned int

Reply
Thread Tools

signed in to unsigned int

 
 
Daz
Guest
Posts: n/a
 
      05-06-2006
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.

 
Reply With Quote
 
 
 
 
Daz
Guest
Posts: n/a
 
      05-06-2006
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.

 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      05-06-2006
Daz wrote:

> 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()


--
Nick Keighley

 
Reply With Quote
 
john
Guest
Posts: n/a
 
      05-06-2006
Daz wrote:
>
> I will remove this post shortly.
>


How does one remove a post from usenet???
 
Reply With Quote
 
Daz
Guest
Posts: n/a
 
      05-06-2006

john wrote:

> Daz wrote:
> >
> > I will remove this post shortly.
> >

>
> 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... )

 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      05-06-2006
"Daz" writes:

> 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.


 
Reply With Quote
 
=?ISO-8859-1?Q?Martin_J=F8rgensen?=
Guest
Posts: n/a
 
      05-06-2006
Daz wrote:
> 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

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
 
Reply With Quote
 
Daz
Guest
Posts: n/a
 
      05-06-2006
osmium wrote:
{
>"Daz" writes:
>> 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.

}


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:
{
> abs()

}


Both very good ideas. Thanks gents! )

Daz

 
Reply With Quote
 
Daz
Guest
Posts: n/a
 
      05-06-2006
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'...

 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      05-06-2006
Daz wrote:
> 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()
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
Convert 32 bit unsigned int to 16 bit signed int. Fore C++ 29 09-21-2008 05:55 AM
comparison between signed int and unsigned int Alex C Programming 3 04-26-2006 05:20 AM
unsigned int with signed long int (same width) - how is conversion done? G Fernandes C Programming 2 02-16-2005 10:55 AM
convert signed int to unsigned int Siemel Naran C++ 3 11-29-2004 08:22 AM



Advertisments