Overload function problem

Hi everybody, i'm having these two errors with the program below;

1) error LNK2019: unresolved external symbol "double__cdeclcalcTotal(int,double)" (?calcTotal@@YANHN@Z) referenced in function _main

2) F:\Practice\C++ Project\Debug\Project-14.exe : fatal error LNK1120: 1 unresolved externals

My problem is that debug output doesn't move me to the line so i can have an idea of the problem.This's the program below;

#include "stdafx.h"
#include<iostream>
#include<iomanip>
using namespace std;

// Function prototypes
void getChoice(char &);
double calcTotal(int, double);
double calcTotal(double);


int main()
{
char selection; // Menu selection
int HospitalStay; // Days in the Hospital
double rate; // Daily rate
double MedicationCharges; // Hospital medication charges
double HospitalSvces; // labs tests



// Set the numeric output formatting.
cout << fixed << showpoint << setprecision(2);

// Display the menu and get a selection.
cout << "patient status \n";
cout << "(I)in-patient, or \n";
cout << "(O)out-patient?\n";
getChoice(selection);

// Process the menu selection.
switch (selection)
{
// in-patient
case 'I':
case 'i': cout << "How many days spent in the hospital?";
cin >> HospitalStay;
cout << "The daily rate";
cin >> rate;
cout << "Hospital medication charges";
cin >> MedicationCharges;
cout << "Charges for hospital services";
cin >> HospitalSvces;
cout << calcTotal( HospitalStay,rate) << endl;
cout << "Total charges is $";
cout << calcTotal(MedicationCharges,HospitalSvces) << endl;
cout << "Total charge is $";
break;


// out-patient
case 'O' :
case 's' : cout << "Charges for hospital services";
cin >> HospitalSvces;
cout << "Hospital medication charges";
cin >> MedicationCharges;
cout << "Total charges is $";
cout << calcTotal( HospitalSvces, MedicationCharges) << endl;
break;
}
return 0;
}


void getChoice(char &letter)
{
// Get the user's selection.
cout << "Enter your choice ( I or O): ";
cin >> letter;
// Validate the selection.
while (letter != 'I' && letter != 'i' && letter != 'O' && letter != 'o')
{
cout << "Please enter I or O: ";
cin >> letter;
}

}
double calcTotal(double rate, int HospitalStay)
{
return rate * HospitalStay;
}
double calcTotal(double MedicationCharges, double HospitalSvces)
{
return MedicationCharges + HospitalSvces;
}

Use code tags like [code]Your code[/code]

Your problem is like usually with linker errors: Your prototype double calcTotal(int, double); differs from your implementation double calcTotal(double rate, int HospitalStay)

Make it the same and you're done
Thanks, it worked; i want to validate input to deny negative numbers for any data. Do u think that i can use counter and strcmp;
FYI, i was able to solved this problem by using the while statement with the following int;

Thanks again.

int HospitalStay; // Days in the Hospital
double rate; // Daily rate
double MedicationCharges; // Hospital medication charges
double HospitalSvces; // labs tests


while ( HospitalStay <= 0)
{
cout << "Please enter a positive number: ";
cin >> HospitalStay;
}


i want to validate input to deny negative numbers for any data. Do u think that i can use counter and strcmp
You can use unsigned int to prevent negativ numbers.
Using unsigned int will not prevent someone calling the function with negative numbers. If you pass a negative number where an unsigned int is expected then it's complement will be used instead giving you an entirely unexpected number.
Topic archived. No new replies allowed.