title: Passing member variables to functions
body: <p>I'm learning about classes and passing member variables to functions from the book "Starting out with C++: Early objects".</p>
  
  <p>Right now, I'm working on a programming challenge in chapter 7 that I just can't seem to wrap my head around.  My issue is I can't seem to pass the <code>speed</code> variable to my <code>accelerate()</code> function and get it to add 5 each time it's used.</p>
  
  <p>I've tried modifying it several different ways, and am probably way off by now. In case you're not understanding what I'm doing, here are the instructions for the challenge:</p>
  
  <blockquote>
    <p>Write a class named Car that has the following member variables:</p>
    
    <p>year. An int that holds the car's model year.</p>
    
    <p>make. A string object that holds the make of the car.</p>
    
    <p>speed. an int that holds the car's current speed.</p>
    
    <p>In additions, the class should have the following member functions.</p>
    
    <p>Constructor. The constructor should accept the car's  year and make as arguments and assign these values to the object's year and make member variables. The constructor should initialize the speed member variable to 0.</p>
    
    <p>Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an objects year, make and speed member variables. </p>
    
    <p>Accelerate. The accelerate function should add 5 from the speed member variable each time it is called.</p>
    
    <p>brake. The brake function should subtract 5 from the speed member variable each time it is called.</p>
    
    <p>Demonstrate the class in a program that creates a Car object and then calls the accelerate function five times. After each call to the accelerate function, get the current speed of the car and display it. Then, call the brake function five times. After each call to the brake function, get the current speed of the car and display it.</p>
  </blockquote>
  
  <p>Here is what I have as of now:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  class Car {
  
  public:
  
  int year, speed;
  string make;
  
  void accelerate(int);
  void brake(int);
  
  string getMake(string);
  int getYear(int);
  int getSpeed(int);
  
  Car(int year, string make, int speed = 0) {
  
  }
  
  Car() {
  
  }
  
  
  
  
  };
  
  void Car::accelerate(int s) {
  speed += 5;
  cout &lt;&lt; "Your speed is " &lt;&lt; s &lt;&lt; endl;
  }
  
  void Car::brake(int speed) {
  speed -= 5;
  }
  
  
  
  string Car::getMake(string) {
  return make;
  }
  
  int Car::getYear(int) {
  return year;
  }
  
  int Car::getSpeed(int) {
  return speed;
  }
  
  int main() {
  
  Car myCar;
  int mySpeed = 0;
  
  myCar.getSpeed(mySpeed);
  
  for (int i = 1; i &lt;= 5; i++) {
  
      myCar.getSpeed(mySpeed);
      myCar.accelerate(mySpeed);
  
  }
  
  }
  </code></pre>