| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Daz" |
| Date: |
06 May 2006 10:13:40 AM |
| Object: |
signed in to unsigned int |
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.
.
|
|
| User: "Nick Keighley" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 10:22:40 AM |
|
|
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
.
|
|
|
| User: "Daz" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 11:20:57 AM |
|
|
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=F8rgensen 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! :o)
Daz
.
|
|
|
| User: "Jim Langston" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 05:20:44 PM |
|
|
"Daz" <cutenfuzzy@gmail.com> wrote in message
news:1146932457.020012.166440@j33g2000cwa.googlegroups.com...
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()
}
Why not just
std::cout << "You have lost " << -lost_money << std::endl;
.
|
|
|
| User: "Daz" |
|
| Title: Re: signed in to unsigned int |
07 May 2006 04:16:27 AM |
|
|
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.
:o)
Thanks everyone!
.
|
|
|
| User: "Olaf van der Spek" |
|
| Title: Re: signed in to unsigned int |
07 May 2006 12:59:11 PM |
|
|
On 7 May 2006 02:16:27 -0700, "Daz" <cutenfuzzy@gmail.com> wrote:
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.
:o)
You didn't think about 0 - lost_money either?
.
|
|
|
|
|
|
| User: "Daz" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 11:23:07 AM |
|
|
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'...
.
|
|
|
|
|
|
| User: "Daz" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 10:19:47 AM |
|
|
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.
.
|
|
|
| User: "osmium" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 10:38:01 AM |
|
|
"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.
.
|
|
|
| User: "Default User" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 05:46:36 PM |
|
|
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.
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.
.
|
|
|
|
|
| User: "john" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 10:22:48 AM |
|
|
Daz wrote:
I will remove this post shortly.
How does one remove a post from usenet???
.
|
|
|
| User: "Daz" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 10:35:40 AM |
|
|
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... :o)
.
|
|
|
|
|
| User: "red floyd" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 04:43:10 PM |
|
|
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()
.
|
|
|
|
| User: "=?ISO-8859-1?Q?Martin_J=F8rgensen?=" |
|
| Title: Re: signed in to unsigned int |
06 May 2006 10:51:01 AM |
|
|
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
.
|
|
|
|
|

|
Related Articles |
|
|