the x value

This is a discussion on the x value within the C++ Programming forums, part of the General Programming Boards category; assuming x is = 10.0 why after this assignment x becomes 210.0 x = x - 20.0 I appreciate the ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    17

    the x value

    assuming x is = 10.0
    why after this assignment x becomes 210.0

    x = x - 20.0

    I appreciate the answer.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,702
    Well, what's the variables type?
    Code:
    bool flip(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() < 0;
    }

  3. #3
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    Re: the x value

    Originally posted by Absy
    assuming x is = 10.0
    why after this assignment x becomes 210.0

    x = x - 20.0

    I appreciate the answer.
    I'll assume that they are doubles scince u have the decimal.

    I believe it would be

    x = 190.0

    Scince x was redefined as 210.0 you just subtract the 20.0 from that as the 10.0 is no longer in the equation.

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    I think Absy meant it became 210 AFTER the equation x=x-20.0

    Somewhere between x=10.0 and x=x-20.0 you have code that is changing the value of x. Post all the code between these two statements and we'll help ya track it down!

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    17

    sorry for the confusion

    Sorry if I confused you all,
    Actually it was a question in one of the chapters Iread,and the question is like like this:

    what value is assigned to x by the statement below assuming x is
    10.0?

    x = x - 20.0;

    when I checked the answer at the end of the chapter it was
    210.0
    I just want to understand why is the answer like that and they did not mention what type the variable is or there is no more code lines thanks again.

  6. #6
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    I'm guessing the value loops back around...
    eg.

    unsigned char mychar = 0;
    mychar -= 10;

    mychar should now equal 245, as 255 is the max value for a char, and subtracting 10 from the min value (0) is going to give you 10 less than the max value. However, I can't think of any variable which has a max value of 220...

    What book is this?

  7. #7
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    It's probably a typo, the answer is -10.0 The 2 was probably printed instead of the -
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    17

    the value of x

    the book is " problem solving abstraction design using C++"
    by frank l. friedman and elliot b. doffman
    it is a text book in Penn State Univ. capitol campus
    thanks for the reply

  9. #9
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    Yeah, tell this guy his book has a typo...
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21