assuming x is = 10.0

why after this assignment x becomes 210.0

x = x - 20.0

I appreciate the answer.

Printable View

- 11-07-2002Absythe x value
assuming x is = 10.0

why after this assignment x becomes 210.0

x = x - 20.0

I appreciate the answer. - 11-07-2002Sebastiani
Well, what's the variables type?

- 11-08-2002RoDRe: the x valueQuote:

*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 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. - 11-08-2002PJYelton
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! - 11-08-2002Absysorry 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. - 11-08-2002Eibro
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? - 11-08-2002OneStiffRod
It's probably a typo, the answer is -10.0 The 2 was probably printed instead of the -

- 11-08-2002Absythe 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 - 11-08-2002OneStiffRod
Yeah, tell this guy his book has a typo...