signed in to unsigned int

Discussion in 'C++' started by Daz, May 6, 2006.

  1. Daz

    Daz Guest

    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.
     
    Daz, May 6, 2006
    #1
    1. Advertising

  2. Daz

    Daz Guest

    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.
     
    Daz, May 6, 2006
    #2
    1. Advertising

  3. 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
     
    Nick Keighley, May 6, 2006
    #3
  4. Daz

    john Guest

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


    How does one remove a post from usenet???
     
    john, May 6, 2006
    #4
  5. Daz

    Daz Guest

    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... :eek:)
     
    Daz, May 6, 2006
    #5
  6. Daz

    osmium Guest

    "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.
     
    osmium, May 6, 2006
    #6
  7. 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
     
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, May 6, 2006
    #7
  8. Daz

    Daz Guest

    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! :eek:)

    Daz
     
    Daz, May 6, 2006
    #8
  9. Daz

    Daz Guest

    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'...
     
    Daz, May 6, 2006
    #9
  10. Daz

    red floyd Guest

    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()
     
    red floyd, May 6, 2006
    #10
  11. Daz

    Jim Langston Guest

    "Daz" <> wrote in message
    news:...
    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;
     
    Jim Langston, May 6, 2006
    #11
  12. Daz

    Default User Guest

    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.
     
    Default User, May 6, 2006
    #12
  13. Daz

    Daz Guest

    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!
     
    Daz, May 7, 2006
    #13
  14. On 7 May 2006 02:16:27 -0700, "Daz" <> 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.
    >:eek:)


    You didn't think about 0 - lost_money either?
     
    Olaf van der Spek, May 7, 2006
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Siemel Naran

    convert signed int to unsigned int

    Siemel Naran, Nov 28, 2004, in forum: C++
    Replies:
    3
    Views:
    34,108
    Ioannis Vranos
    Nov 29, 2004
  2. G Fernandes
    Replies:
    2
    Views:
    494
    Lawrence Kirby
    Feb 16, 2005
  3. Alex
    Replies:
    3
    Views:
    647
    Michael Mair
    Apr 26, 2006
  4. Fore
    Replies:
    29
    Views:
    15,283
    Rashad
    Sep 21, 2008
  5. pozz
    Replies:
    12
    Views:
    746
    Tim Rentsch
    Mar 20, 2011
Loading...

Share This Page