Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Christos

  • one year ago

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

  • This Question is Closed
  1. Christos
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    #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; }

  2. eSpeX
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

  3. Christos
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    So whats the difference between != and =! ?

  4. eSpeX
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

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

  5. eSpeX
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

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

  6. Christos
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    thank you

  7. eSpeX
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    You're welcome.

  8. Not the answer you are looking for?
    Search for more explanations.

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.