# Thread: the x value

1. ## 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. Well, what's the variables type?

3. ## 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. 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. ## 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. 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. It's probably a typo, the answer is -10.0 The 2 was probably printed instead of the -

8. ## 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. Yeah, tell this guy his book has a typo...

Popular pages Recent additions