我的C++函数不断收到调试错误。我不确定我做错了什么
I keep getting debugging errors for my C++ function. I'm not sure what I'm doing wrong
嗨,我对编程很陌生,对于这个程序,我应该能够使用函数计算某人的每月费用。当我编译它时,它很好,但是当我尝试调试时,它说我失败了,所以我无法判断我做错了什么。这是我的代码:
该程序计算用户的月费
#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;
}
但是每当我尝试调试它时,我都会收到错误消息:
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:UserscharlotteDesktopprogram5Debugprogram5.exe : fatal error LNK1120: 2 unresolved externals
第一个错误是编译器决定需要将double
类型传递给calculatePkg_C
。 它期望:
calculatePkg_C(double,double,double)
但你的是:
calculatePkg_C(int,int,int)
你需要问问自己为什么会这样。 您已在顶部声明了它,并在下面正确定义了它。 有什么东西你没有展示吗? 我注意到你正在通过inputHours
这是一个double
. 尝试将其转换为int
。
另一个错误是 showPackage
. 您的声明(和用法)的大小写错误。
错误消息告诉我们您已声明calculatePkg_C(double,double,double)
但您实现了calculatePkg_C(int,int,int)
。更改定义中的原型,它应该可以工作。此外,查找声明此原型的函数的位置。
您需要检查每种构建类型的生成属性。包含 caclulatePkg_C()
和 showpackage()
方法的源文件位于发布配置中,但不在调试配置中。
我很担心你声明你的三个函数在他们的原型中采用三个 int 参数:
void calculatePkg_A (int,int,int);
void calculatePkg_B (int,int,int);
void calculatePkg_C (int,int,int);
但是您肯定会将它作为第三个参数传递给它,因为您声明:
double inputHours; //number of hours
我不建议在这里进行任何转换,如果您必须保留函数原型,最好将其声明为整数。
在 showpackage 实现中,请记住 C/C++ 具有区分大小写的 sintax,因此您应该编写:
//definition of function showPackage which displays package options
void showPackage()
{
...
}
相关文章:
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 不确定出了什么问题(字符串输入)
- 代码输出随机符号,我不确定出了什么问题
- 存在内存访问异常,但我不确定我的代码中出了什么问题
- 不确定我的排序算法出了什么问题
- 我在变量上收到 3 个 C4703 错误,我认为我已经正确初始化了,但我不确定我错过了什么
- 不确定我在阅读文本文件时的问题是什么
- 我不确定这些错误消息是什么意思
- 试图在每次输出后使用一个函数摆脱'0',但不确定我可以返回什么
- 对于不确定值的无符号字符类型,标准中特殊语言对于左值到右值的转换有什么意义?
- 我不确定我做错了什么,但我不断收到错误 c++
- 值未存储在向量中 - 不确定这里发生了什么
- 不确定 c++ 中的常量函数是什么
- 我的C++函数不断收到调试错误。我不确定我做错了什么
- 视觉C++不确定我在做什么来获得这些错误
- 不断收到有关类型匹配的错误.不确定这意味着什么或如何解决它
- C++-CString不确定为转储html源设置什么值
- 什么是C++中的不确定行为?它与未定义的行为有何不同
- C++考试修订版,不确定为什么正确答案是什么
- 我想从这段代码中删除使用命名空间std,但我不确定什么都需要用std::作为前缀