I need help fixing my code. I'm getting the following errors: 107 C:\Dev-Cpp\TicketFineCalculator.cpp no matching function for call to `TicketFineCalculator::getFine(int&)' and note C:\Dev-Cpp\TicketFineCalculator.cpp:20 candidates are: int TicketFineCalculator::getFine(int, int, int, int)

Here is my code:

#include <iostream> //allows program to perform input and ouput
#include <string>   //allows string
using namespace std;

class  TicketFineCalculator
{

public:

 // Constructor

 TicketFineCalculator(int processingFee);

 // Calculate the total fine given the road zone, speed limit, and the vehicle's actual speed.

 // Return the fine as an integer.

 int getFine(int speedingType, int speedLimit, int vehicleSpeed, int totalFine)

 {

 if (speedingType = 1) // Regular Speed zone-- Fine: $5 per mile over speed limit

    {

        totalFine = (vehicleSpeed - speedLimit)*5;

    }

 if (speedingType = 2) // Work zone-- Fine: $6 per mile over speed limit, plus $120 

    {

        totalFine = (vehicleSpeed - speedLimit)*6 + 120;

    }

 if (speedingType = 3) // Residential zone-- Fine: $7 per mile over speed limit, plus $60 

    {

        totalFine = (vehicleSpeed - speedLimit)* 7 + 60;

    }

 return totalFine;

 }

private:

 // Speeding ticket processing fee.

 int processingFee;

};

int main ()

{

  TicketFineCalculator myTicketFineCalculator(100);  //where I created the instance of the class !!!!!!!!!!!!!

  int processingFee;

  int speedingType;

  int speedLimit;

  int vehicleSpeed;

  int totalFine;

  int sentinalValue;

  cout << "-------------------------------" << endl;

 cout << "Speeding Ticket Fine Calculator" << endl;

  cout << "-------------------------------" << endl;

  cout << "Enter processing fee, in dollars:";

  cin >> processingFee;

  int ticketNumber = 1;

  do

  {

  cout << "Speeding Ticket #" << ticketNumber << endl;

   cout << "Enter the type of speeding offense (1 for regular, 2 for work zone, 3 for residential district):";

  cin >> speedingType;


  cout << "Enter the speed limit, in miles per hour:";

  cin >> speedLimit;

  cout << "Enter the vehicle's speed, in miles per hour:";

  cin >> vehicleSpeed;

  totalFine = myTicketFineCalculator.getFine(totalFine);  //This is where i am having issues calling the function 

  cout << "The total fine is: " << totalFine + processingFee << endl;

  // Sentinal value used to stop or continue the program

  cout << "Enter 1 to process another speeding ticket or 0 to quit:";

  cin >> sentinalValue;


  ticketNumber++;//Increases the ticket number if the caluclator runs again

  }

  while (sentinalValue != 0);

  return 0;

}

Compare the parameter list of the function on line 18 with what you are trying to do on line 107. The number of parameters on line 107 must be the same as on line 18, and of the same data types.

line 18: why is totalFine a parameter to the function? Isn't totalFine what that function is supposed to calculate? It would make more sense if the function parameters were like this:

int getFine(int speedingType, int speedLimit, int vehicleSpeed)
{
   int totalFine = 0;
   ...
   ...
}   

Also, the if statements on lines 22, 30 and 38 are incorrect. Use == operator, not the = assignment operator. That would actually be better as a switch statement.

I made the changes as you suggested but I'm getting errors.

Here is what I changed line 107 to

totalFine = myTicketFineCalculator.getFine(speedingType, speedLimit, 
vehicleSpeed);

Also changed the = to == in line 22, 30, and 38

Changed line 18 -20 to

 int getFine(int speedingType, int speedLimit, int vehicleSpeed)
 {
 int totalFine = 0; 

Here are the errors I'm getting:

 C:\Users\addison\AppData\Local\Temp\ccOOeaaa.o(.text+0x152) In function 
 `main':
    [Linker error] undefined reference to 
    `TicketFineCalculator::TicketFineCalculator(int)'
    C:\Users\addison\AppData\Local\Temp\ccOOeaaa.o(.text+0x152) ld
    returned 1 exit status

The linker cannot find the function
TicketFineCalculator::TicketFineCalculator(int)

Something in your code is trying to call that function, and either it doesn't exist, or you haven't compiled the code containing it, or you have compiled it but the linker isn't being told about the compiled file.

Start with the easiest possibilites; should you be calling that function, where are you calling it, should you be calling something else?

I told you about 21 hours ago what's wrong, there is no function named getFine() that has only one parameter, or at least you didn't post one.

At Ancient Dragon...I made the changes you told me and then I'm getting linker error. I am new to C++.

Read the first sentence I wrote

Compare the parameter list of the function on line 18 with what you are trying to do on line 107. The number of parameters on line 107 must be the same as on line 18, and of the same data types.

The function takes 3 parameters, not just one. Or is there another version of that same function that you have not posted which takes only one parameter?

Line 18
    int getFine(int speedingType, int speedLimit, int vehicleSpeed)

Line 107
    totalFine = myTicketFineCalculator.getFine(speedingType, speedLimit, 
    vehicleSpeed)

If I remove the myTicketFineCalculator then I get an error that getFine() isn't declared.

If I remove the myTicketFineCalculator then I get an error that getFine() isn't declared.

I didn't ask you to remove myTicketFineCalulator from that line. Just change the number of parameters.

totalFine = myTicketFineCalculator.getFine(totalFine); //This is where i am having issues calling the function

That is from your original post -- have you changed it? Maybe you should repost the code snippet that you originally posted so we can see what changes you made.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.