0

I am trying to execute the code inside of a .h File by creating an object.. What am I doing wrong?

    //TicketFineCalculator.h
#include <iostream>
using namespace std;

class TicketFineCalculator
{

    public:
int getFine() {
        int procFee, zone, speedLimit, actualSpeed, totalFine;
     int anotherRun = 1;
     while (anotherRun == 1){
cout << "\n-------------------------------";
cout << "\nSpeeding Ticket Fine Calculator";
cout << "\n-------------------------------";
cout << "\nEnter processing fee, in dollars:";
cin >> procFee;
cout << "\nSpeeding Ticket #1";
cout << "\nEnter the type of speeding offense (1 for regular, 2 for work zone, 3 for residential district):";
cin >> zone;

cout << "\nEnter the speed limit, in miles per hour:";
cin >>  speedLimit;
cout << "\nEnter the vehicle's speed, in miles per hour:";
cin >> actualSpeed;
cout << "\nThe total fine is:" << totalFine;
cout << "\nEnter 1 to enter process another speeding ticket or 0 to quit:";
cin >> anotherRun;
     } // terminates while loop
return totalFine; 
        }
 // Calculate the total fine given the road zone, speed limit, and the vehicle's actual speed.
 // Return the fine as an integer.

};


//Project1.cpp
#include <iostream>
#include "TicketFineCalculator.h"

int totalFine;
TicketFineCalculator::getFine(totalFine);

    int main(){
    cout << totalFine;
return 0;
} //terminates main
jam
  • 3,640
  • 5
  • 34
  • 50
CryptoJones
  • 734
  • 3
  • 11
  • 33

1 Answers1

1

If you want to call the getFine() method within TicketFineCalculator, you must declare the method static as in:

class TicketFineCalculator
{
public:
    static getFine()
    {
    }
};

or you must create an instance of TicketFineCalculator and call the method using that instance.

Lou
  • 1,955
  • 14
  • 16
  • Do you mean call it within Project1? If so, how do I create an instance of the class? That is what I thought I did. – CryptoJones Apr 09 '12 at 04:21