title: C++ Member Variables not Updating - Noob here
body: <p>I've lurked and browsed for a while around here already, but this is my first time posting. Hope I've got the rules and format down pat.</p>
  
  <p>I'm been coding for several months now, so still pretty new at this. Right now, I'm trying to implement a very basic parkingmeter class, with only 2 functions. One to insert quarters, and one to check remaining time. Member variables are maxTime, rate, and time.</p>
  
  <p>I got some functionality up and running, but it kept giving me strange results with my checkTime function. I tested at almost every line, and I realize that after I exit the constructor, the values I entered disappear and are replaced with a really long number. I can't figure out why this is happening. It's not my first time using classes, constructors, instantiating objects, and such, and I don't see what I've done differently this time. </p>
  
  <p>Could any of you experts let me know where I've messed up?</p>
  
  <p>Here's my header file:</p>
  
  <pre><code>#ifndef PARKINGMETER_H_INCLUDED
  #define PARKINGMETER_H_INCLUDED
  
  #ifndef PARKINGMETER_H_INCLUDED
  #define PARKINGMETER_H_INCLUDED
  
  class ParkingMeter {
  private:
      int maxTime;
      double time, rate;
  
  public:
      ParkingMeter();
      ParkingMeter(int, double);
      ~ParkingMeter();
      void insertQtrs(int);
      double checkTime(double);
      double getTime();
      void setTime(double);
  
  };
  </code></pre>
  
  <p>And here's my implementation:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdexcept&gt;
  #include &lt;ctime&gt;
  #include "ParkingMeter.h"
  
  using namespace std;
  
  ParkingMeter::ParkingMeter() {       //default constructer
      maxTime = 120;
      rate = .25;
      time = 0;
  }
  
  ParkingMeter::ParkingMeter (int maxTime, double rate) {       //constructor
      maxTime = maxTime;
      rate = rate;
      cout&lt;&lt;"maxTime is "&lt;&lt;maxTime&lt;&lt;endl;
      cout&lt;&lt;"rate is "&lt;&lt;rate&lt;&lt;endl;
  }
  
  ParkingMeter::~ParkingMeter(){      //destructor
  }
  
  void ParkingMeter:: insertQtrs(int quarters){
      ParkingMeter test(this-&gt;maxTime, this-&gt;rate);
      cout&lt;&lt;"maxTime is "&lt;&lt;test.maxTime&lt;&lt;endl;
      cout&lt;&lt;"rate is "&lt;&lt;test.rate&lt;&lt;endl;
      cout&lt;&lt;"You have inserted: "&lt;&lt;quarters&lt;&lt;" quarters."&lt;&lt;endl;
      double time = quarters * (rate * 60);
      if ( time &gt; 120)
          time = 120;
      this -&gt;setTime(time);
  
  }
  
  double ParkingMeter:: checkTime (double startTime){
      ParkingMeter test(this-&gt;maxTime, this-&gt;rate);
      double elapsed = clock() - startTime;
   //   test.maxTime = this-&gt;maxTime;
      cout&lt;&lt;"test: "&lt;&lt;test.maxTime&lt;&lt;endl;
      cout&lt;&lt;"elapsed time: "&lt;&lt;elapsed&lt;&lt;endl;
      cout&lt;&lt;"meter time: "&lt;&lt;time&lt;&lt;endl;
      cout &lt;&lt;"Your remaining time is: "&lt;&lt; (time - (elapsed / ((double)CLOCKS_PER_SEC)));
  }
  
  /*double ParkingMeter:: getTime (){
      int time = this-&gt; maxTime;
      cout&lt;&lt;"time: "&lt;&lt;time&lt;&lt;endl;
      return time;
  }*/
  
  void ParkingMeter:: setTime (double time){
      this -&gt;time = time;
  }
  
  int main () {
      double maxTime, rate;
      int quarters;
      char y;
  
      cout&lt;&lt;"Please enter the max parking time and rate, separated by a space: "&lt;&lt;endl;
      cin&gt;&gt;maxTime&gt;&gt;rate;
      ParkingMeter meter(maxTime, rate);
      cout&lt;&lt;"Please enter the amount of quarters you wish to enter: "&lt;&lt;endl;
      cin&gt;&gt;quarters;
      clock_t start = clock();
      meter.insertQtrs(quarters);
      cout&lt;&lt;"Please enter Y to check remaining time: "&lt;&lt;endl;
      cin&gt;&gt;y;
  
      if (y == 'y'){
         double startTime = start;
          cout&lt;&lt;"starttime: "&lt;&lt;startTime&lt;&lt;endl;
          meter.checkTime (startTime);
      }
  
  
  
  }
  </code></pre>