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
#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; }
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.
So whats the difference between != and =! ?
!= is a defined operator and =! isn't.
It might set your counter variable to 0 because it is interpreted as counter = false
thank you
You're welcome.
Join our real-time social learning platform and learn together with your friends!