0

this is my first time posting here, so be a little gentle ok? Also, I am taking my first programming class, and though I understand everything we are doing in class, a lot of the stuff I read on here is over my head. If you could please try to keep your answers as basic as possible I would appreciate it.

With that said, I am doing C++ programming, using code blocks on a mac.

This is the error I am getting from code blocks

Undefined symbols for architecture x86_64:
"totalBill(double, char, double&, double&, double&, double&)", referenced from:
  _main in Watkins-wk6-prog1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

I will also post the code so you can take a look and see if that sheds any light.

#include <iostream>
#include <iomanip>
#include <cctype>

using namespace std;

//Global Constants

double const COM_PRICE = 22.91;
double const MID_PRICE = 25.76;
double const FULL_PRICE = 28.87;
double const SUV_PRICE = 98.88;
int const COM_MILES = 20;
int const MID_MILES = 25;
int const FULL_MILES = 30;
string const SUV_MILES = "Unlimited";
double const COM_OVER_MILES = 0.05;
double const MID_OVER_MILES = 0.07;
double const FULL_OVER_MILES = 0.09;
string const SUV_OVER_MILES = "N/A";
int const WEEK = 7;
double const WEEK_RATE = 6.5;
double const TAX = .115;
string const PROMPT1 = "Enter the number of days for the rental";
string const PROMPT2 = "Enter the number of miles driven";
string const PROMPT3 = "Enter the type of car to be rented (C,M,F,S)";


// function prototypes
char carSize(string prompt);
double inputs (string prompt);
double ChargeForCar(char carType, int numDays);
double carPrice (char carType);
double ChargeforMiles(double miles, char carType);
void totalBill(double miles, char carType, double& taxTotal, double& mileCharge, double&         
               grandTotal, double& carCharge);
string carSize (char carType);
void billOutput(string carTypeName, int numDays, double miles, double carCharge, double          
milageCharge, double taxTotal, double grandTotal);


int main()
{
  int numDays;    // number of days of rental
  int weeks   ;   // number of weeks in rental period
  int extraDays;  // number of extra days if car rented for more than a week
  double mileCharge = 0;
  double carCharge = 0;
  double taxTotal = 0;
  double grandTotal = 0;
  char carType;
  double miles;
  string carTypeName;

  cout << "Program to calculate the charge for a rental car." << endl << endl;

  carType = carSize(PROMPT3);   // calls function to get the type of car from
                              // the user
  numDays = static_cast<int> (inputs(PROMPT1));     // calls function to get number of days  in            
                                                    //the rental period
  miles = inputs(PROMPT2);       // calls function to get number of mile driven
                             // during rental period


      // calls function to calculate the total rental car bill
  totalBill(miles, carType, taxTotal, grandTotal, mileCharge, carCharge);

  carTypeName = carSize(carType);  // calls function to save car size as string

    //calls function to output the bill componenets
  billOutput(carTypeName, numDays, miles, carCharge, mileCharge, taxTotal, grandTotal);

  return 0;
}

char carSize(string prompt)  // function to present car choices and read in user input
{
  char carType;
  bool valid = false;


  cout << "Type of Car" << setw(16) << "Price per day" << setw(15);
  cout << "Included Milage" << setw(24) << "Extra charge per mile" << endl;
  cout << setw(66) << setfill ('-') << "-" << endl;
  cout << setfill(' ') << "C - Compact size" << setw(8) << COM_PRICE;
  cout << setw(5) << COM_MILES << setw(5) << COM_OVER_MILES << endl;
  cout << "M - Mid-Size" << setw(8) << MID_PRICE;
  cout << setw(5) << MID_MILES << setw(5) << MID_OVER_MILES << endl;
  cout << "F - Full size" << setw(8) << FULL_PRICE << setw(5) ;
  cout << FULL_MILES << setw(5) << FULL_OVER_MILES << endl;
  cout << " S - SUV" << setw(8) << SUV_PRICE << setw(5) ;
  cout << SUV_MILES << setw(5) << SUV_OVER_MILES << endl;

  do
  {
    cout << prompt ;
    cin >> carType;

    carType = toupper(carType);

    switch(carType)
    {
    case 'C':
    case 'F':
    case 'M':
    case 'S':
        valid = true;
        break;
    default:
        cout << "Invalid entry.  Please enter a letter from the list";
        break;
    }

  }
  while (valid == false);

  return carType;
}

double inputs(string prompt)  // general function to read a prompt and output user input
{
  double input;

  do
  {
    cout << prompt;
    cin >> input;

    if (input <= 0)
    {
        cout << "Invalid input." << endl;
        cout << "Please enter a positive, nonzero interger." << endl;
    }
  }
  while (input <= 0);

  return input;
}

double ChargeForCar(char carType, int numDays)  // function to calculate the charge for the  
                                                //rental period
{
  double carCharge;
  int weeks;
  int extraDays;
  double carRate;

  carRate = carPrice(carType);

  if (numDays >= WEEK)
  {
    weeks = numDays / WEEK;
    extraDays = numDays % WEEK;
    carCharge = (weeks * WEEK_RATE * carRate) + (extraDays * carRate);
  }
  else
  {
    carCharge = carRate * numDays;
  }

  return carCharge;
}

double carPrice (char carType)  // function to determine which price to use for rental car
{
  double carRate;

  switch (carType)
  {
  case 'C':
    carRate = COM_PRICE;
    break;
  case 'F':
    carRate = FULL_PRICE;
    break;
  case 'M':
    carRate = MID_PRICE;
    break;
  case 'S':
    carRate = SUV_PRICE;
    break;
  default:
    cout << "Unknown car type" << endl;
    break;
  }

  return carRate;
}

double ChargeForMiles(double miles, char carType)  // function to calculate the extra milage 
                                                   //cost
{
  double milesCost;
  double extraMiles;

  switch(carType)
  {
  case 'C':
    if (miles > COM_MILES)
    {
        extraMiles = miles - COM_MILES;
        milesCost = extraMiles * COM_OVER_MILES;

    }
    else
    {
        milesCost = 0;
    }
    break;
  case 'F':
    if (miles > FULL_MILES)
    {
    extraMiles = miles - FULL_MILES;
    milesCost = extraMiles * FULL_OVER_MILES;
    }
    else
    {
        milesCost = 0;
    }
    break;
  case 'M':
    if (miles > MID_MILES)
    {
        extraMiles = miles - MID_MILES;
        milesCost = extraMiles * MID_OVER_MILES;
    }
    else
    {
        milesCost = 0;
    }
    break;
  }

  return milesCost;
}

void totalBill(double miles, double numDays, char carType, double& taxTotal, double& mileCharge,   
                double& grandTotal, double& carCharge)  

// function to calculate the program totals
{
  switch(carType)
  {
    case 'C':
    case 'M':
    case 'F':
        mileCharge = ChargeForMiles(miles, carType);
        break;
    default:
        mileCharge = 0;
        break;
  }
  carCharge = ChargeForCar(carType, numDays);  // call to the function to calculate the charge            
                                               //for the rental car

  taxTotal = (mileCharge + carCharge) * TAX;
  grandTotal = mileCharge + carCharge + taxTotal;
}

string carSize(char carType) //function for setting car type name as a string type
{
  string typeName;

  if (carType == 'C')
  {
    typeName = "Compact size";
  }
  else if (carType == 'M')
  {
    typeName = "Mid size";
  }
  else if (carType == 'F')
  {
    typeName = "Full size";
  }
  else if (carType == 'S')
  {
    typeName = "SUV size";
  }

  return typeName;
}

void billOutput(string carTypeName, int numDays, double miles, double carCharge, double 
                milageCharge, double taxTotal, double grandTotal)
{
  cout << "Rent2U Rental Details" << endl << endl;
  cout << "Car Size: " << carTypeName << endl;
  cout << "Days Rented" << numDays << "days" << endl;
  cout << "Miles Driven" << miles << "miles" << endl << endl;

  cout << "BILL" << endl;
  cout << "Car Charge" << "$" << carCharge << endl;
  cout << "Mialge Charge" << "$" << milageCharge << endl;
  cout << "Tax" << "$" << taxTotal << endl;
  cout << setw(21) << " " << setw(11) << setfill('-') << "-" << endl;
  cout << setfill(' ') << "Total Bill" << "$" << grandTotal << endl << endl;
}

1 Answer 1

3

It's because your implementation of totalBill has a different signature (i.e. different parameters) from the declaration. One takes two doubles then a char and the other, one double then a char. They need to match.

Sign up to request clarification or add additional context in comments.

2 Comments

Yup. A good way to prevent this thing from happening is writing the function out first and then when you get it good and working, copy the signature, paste it where you have your prototypes, and put a semicolon at the end. Then, just move the function where ever you want.
Thanks guys! Really appreciate it. Thought I had looked at that, but after 6 hours of programming my eyes must have just missed it. I will do what you suggest from now on to avoid it happening again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.