Oct 13, 2009 at 6:28am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
//functions.cpp
#include <iostream>
using namespace std;
bool isValidPkg( char p ) //checkpkg
{
return (p>='A' && p<='C' ) || (p>='a' && p<='c' );
}
char getValidPkg() //getpkg
{
char p=0;
do
{
cout<<"Enter pkg: " ;
cin>>p;
}
while ( !isValidPkg(p) );
return p;
}
bool isValidHrs( int h ) //checkhrs
{
return (h>=0 && h<=720);
}
char getValidHrs() //gethrs
{
int h;
do
{
cout<<"Enter hours: " ;
cin>>h;
}
while ( !isValidHrs(h) );
return h;
}
double calculateCharges(int h, char p) //calculatecharges
{
double sum;
switch (p)
{
case 'a' :
sum=15+(h-50)*2;
break ;
case 'A' :
sum=15+(h-50)*2;
break ;
case 'b' :
sum=20+(h-100)*1.5;
break ;
case 'B' :
sum=20+(h-100)*1.5;
break ;
case 'c' :
sum=25+(h-150)*1;
break ;
case 'C' :
sum=25+(h-150)*1;
break ;
}
return sum;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
//program5.cpp
#include <iostream>
using namespace std;
#include "functions.h"
void main()
{
char pkg;
pkg = getValidPkg();
cout<<"Pkg: " <<pkg<<endl;
int hrs;
hrs = getValidHrs();
cout<<"Hrs: " <<hrs<<endl;
double sum;
sum = calculateCharges();
cout<<"Bill: " <<sum<<endl;
}//endmain
1 2 3 4 5 6 7
//functions.h
char getValidPkg();
char getValidHrs();
double calculateCharges();
Error 1 error LNK2019: unresolved external symbol "double __cdecl calculateCharges(void)" (?calculateCharges@@YANXZ) referenced in function _main program5.obj
Error 2 fatal error LNK1120: 1 unresolved externals C:\Users\mattb\Documents\Visual Studio 2008\Projects\program5\Debug\program5.exe
Last edited on Oct 13, 2009 at 12:19pm UTC
Oct 13, 2009 at 6:38am UTC
it is as it says:
unresolved external symbol double calculateCharges(void)
Where is this function?
Oct 13, 2009 at 6:45am UTC
in my main, which is program5.cpp right? so-
double sum;
sum = calculateCharges('something goes in here'???);
cout<<"Bill: "<<sum<<endl;
Oct 13, 2009 at 7:56am UTC
yes, because you have defined a calculateCharges function to take 2 parameters .See line 45 in your original code posting.
Oct 13, 2009 at 12:16pm UTC
now i get two errors for "expected primary expression" before int and char in the main
Oct 13, 2009 at 2:53pm UTC
line 19: sum = calculateCharges(hrs, pkg);
'calculateCharges' is taking two arguments when you call it, but its definition states that it doesn't take any.
Change in functions.h line 7 to: double calculateCharges(int h, char p);
Last edited on Oct 13, 2009 at 2:57pm UTC
Oct 13, 2009 at 2:56pm UTC
You need to change the declaration of calculateCharges
inf functions.h to match the actual definition in functions.cpp. They can't be different, the have to be the same.