Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (christos):

While debugging this code I have noticed that at some specific point (info below) my variable with the name "counter" is changing from "1" to "0" for no specific reason. There: http://screencast.com/t/1pWDfHHqc Do you know why? I don't get it

OpenStudy (christos):

#include <iostream> using namespace std; int main() { int years,counter=0; double ValueCar; cout << "Value : "; cin >> ValueCar; cout << "Years : "; cin >> years; while (counter <= years) { counter++; if (counter == 1) ValueCar = ValueCar-ValueCar*30/100; if ((counter =! 1) && (counter <=8)) ValueCar = ValueCar - ValueCar*10/100; if (counter > 8) ValueCar = ValueCar - ValueCar*5/100; } if (ValueCar < 500) ValueCar = 500; cout << "The value of that car is " << ValueCar; return 0; }

OpenStudy (espex):

I would guess it has something to do with your condition, if((counter =! 1), the operator should be != and I can't say for certain how it would react with the way you have it.

OpenStudy (christos):

So whats the difference between != and =! ?

OpenStudy (espex):

!= is a defined operator and =! isn't.

OpenStudy (espex):

It might set your counter variable to 0 because it is interpreted as counter = false

OpenStudy (christos):

thank you

OpenStudy (espex):

You're welcome.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!