Reputation: 67
Hi, I'm very new to programming, for this program i am supposed to be able to calculate someone's monthly charges by using functions. When I compile it it's fine, but when I try to debug it says I've failed so I can't tell what I'm doing wrong. Here is my code:
//this program calculates a user's monthly charges
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
void showpackage();
void calculatePkg_A (int,int,int);
void calculatePkg_B (int,int,int);
void calculatePkg_C (int,int,int);
int main ()
{
int inputPackage; //package choice
double inputHours; //number of hours
//constants for package choice
const int pkg_A = '1' ,
pkg_B = '2',
pkg_C = '3';
const char quit_choice = 'Q' || 'q';
//constants for cost of package
const int cost_A = 15,
cost_B = 20,
cost_C = 25;
//constants for package access time
const int hours_A = 50,
hours_B = 100,
hours_C = 150;
cout << fixed << showpoint << setprecision (2);
do
{ //display package options.
showpackage();
cin >> inputPackage;
//validate package selection
while (inputPackage < pkg_A || inputPackage > pkg_C || inputPackage != quit_choice )
{
cout << "Please enter a valid package choice:";
cin >> inputPackage;
}
//If user does not want to quit, proceed.
if (inputHours < 0 || inputHours > 720 || inputPackage != quit_choice)
{
//get the number of hours used
cout << "How many hours were used?";
cin >> inputHours;
//display the total charges
switch (inputPackage)
{
case pkg_A:
calculatePkg_A (cost_A, hours_A, inputHours);
break;
case pkg_B:
calculatePkg_B (cost_B, hours_B, inputHours);
break;
case pkg_C:
calculatePkg_C (cost_C, hours_C, inputHours);
break;
}
}
} while (inputPackage != quit_choice);
return 0;
}
//definition of function showPackage which displays package options
void showPackage()
{cout <<"An Internet service provider has three different packages for its customers: \n"
<<"1.Package A: For $15 per month with 50 Hours of access provided, additional hours \n"
<<"are $2.00 per hour over 50 hours.\n"
<<"2.Package B: For $20 per month with 100 Hours of access provided, additional hours \n"
<<"are $1.50 per hour over 100 hours.\n"
<<"3.Package C: For $25 per month with 150 Hours of access provided, additional hours \n"
<<"are $1.00 per hour over 150 hours.\n"
<<"Enter your choice either 1,2, or 3:";
}
//defintion of function calculatePkg_A. Displays total charges.
void calculatePkg_A (int cost_A, int hours_A, int inputHours)
{
cout << "The total charges are $"
<< (cost_A += (inputHours - hours_A) * 2) << endl;
}
//
//defintion of function calculatePkg_B. Displays total charges.
//
void calculatePkg_B (int cost_B, int hours_B, int inputHours)
{
cout << "The total charges are $"
<< (cost_B += (inputHours - hours_B) * 1.5) << endl;
}
//defintion of function calculatePkg_C. Displays total charges.
void calculatePkg_C (int cost_C, int hours_C, int inputHours)
{
cout << "The total charges are $"
<< (cost_C += (inputHours - hours_C)) << endl;
}
But whenever i try to debug it I keep getting the error message:
1>Program5.obj : error LNK2019: unresolved external symbol "void __cdecl calculatePkg_C(double,double,double)" (?calculatePkg_C@@YAXNNN@Z) referenced in function _main
1>Program5.obj : error LNK2019: unresolved external symbol "void __cdecl showpackage(void)" (?showpackage@@YAXXZ) referenced in function _main
1>C:\Users\charlotte\Desktop\program5\Debug\program5.exe : fatal error LNK1120: 2 unresolved externals
Upvotes: 1
Views: 200
Reputation: 11
I'm shure that you declare your three function as taking three int parameters in their prototypes:
void calculatePkg_A (int,int,int);
void calculatePkg_B (int,int,int);
void calculatePkg_C (int,int,int);
but you surely pass it a double as third parameter, because you declare:
double inputHours; //number of hours
I don't recommend any cast here, your better declare it as integer if you must keep function prototypes.
In showpackage implementation, remember C/C++ has a case sensitive sintax, thus you should write:
//definition of function showPackage which displays package options
void showPackage()
{
...
}
Upvotes: 0
Reputation: 63471
First error is that the compiler decided you need to pass double
types to calculatePkg_C
. It expects:
calculatePkg_C(double,double,double)
But yours is:
calculatePkg_C(int,int,int)
You need to ask yourself why this would be. You've declared it at the top, and defined it below correctly. Is there something you are not showing? I notice you are passing inputHours
which is a double
. Try casting that as an int
.
The other error is showPackage
. Your declaration (and usage) has the wrong capitalisation.
Upvotes: 1
Reputation: 258608
The error message tells us that you've declared calculatePkg_C(double,double,double)
but you implemented calculatePkg_C(int,int,int)
. Change the prototype in the definition and it should work. Also, look for where the function with this prototype is declared.
Upvotes: 1
Reputation: 39807
You need to examine the build properties for each of your build types. The source file(s) that contain your caclulatePkg_C()
and showpackage()
methods is in your Release configuration, but not your Debug configuration.
Upvotes: 0