assuming x is = 10.0

why after this assignment x becomes 210.0

x = x - 20.0

I appreciate the answer.

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 ...

- 11-07-2002 #1

- 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.

- 11-07-2002 #2
Well, what's the variables type?

Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }

- 11-08-2002 #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 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-2002 #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!

- 11-08-2002 #5

- 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.

- 11-08-2002 #6

- 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?

- 11-08-2002 #7
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..."

- 11-08-2002 #8

- 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

- 11-08-2002 #9
Yeah, tell this guy his book has a typo...

My Avatar says: "Stay in School"

Rocco is the Boy!

"SHUT YOUR LIPS..."

- Exactly how to get started with C++ (or C) today
- C Tutorial
- C++ Tutorial
- 5 ways you can learn to program faster
- The 5 Most Common Problems New Programmers Face
- How to set up a compiler
- 8 Common programming Mistakes
- What is C++11?
- Creating a game, from start to finish

- How to create a shared library on Linux with GCC - December 30, 2011
- Enum classes and nullptr in C++11 - November 27, 2011
- Learn about The Hash Table - November 20, 2011
- Rvalue References and Move Semantics in C++11 - November 13, 2011
- C and C++ for Java Programmers - November 5, 2011
- A Gentle Introduction to C++ IO Streams - October 10, 2011