在if参数内调用bool函数 p>所以我有一个C++布尔函数,我写的这个函数是: bool EligibileForDiscount(const char CompanyUsed, const char CompanySubscribed) { bool eligible = false; if (CompanyUsed==CompanySubscribed) eligible = true; return (eligible); } bool EligibleForDiscount(const char CompanyUsed, const char CompanySubscribed) { return CompanyUsed==CompanySubscribed; }

在if参数内调用bool函数 p>所以我有一个C++布尔函数,我写的这个函数是: bool EligibileForDiscount(const char CompanyUsed, const char CompanySubscribed) { bool eligible = false; if (CompanyUsed==CompanySubscribed) eligible = true; return (eligible); } bool EligibleForDiscount(const char CompanyUsed, const char CompanySubscribed) { return CompanyUsed==CompanySubscribed; },c++,if-statement,g++,boolean,C++,If Statement,G++,Boolean,现在,在my main()中,此函数作为if语句的唯一参数调用: if (EligibleForDiscount(CompanyUsed, CompanySubscribed)) { ApplyDiscount(Cost, CompanySubscribed); cout << "\nAfter your discount, your rental is: $" << fixed <

现在,在my main()中,此函数作为if语句的唯一参数调用:

   if (EligibleForDiscount(CompanyUsed, CompanySubscribed))
       {
           ApplyDiscount(Cost, CompanySubscribed);
           cout << "\nAfter your discount, your rental is: $"
           << fixed << showpoint << setprecision(2) << Cost << ".\n";
       }
if(可删除的fordiscount(公司已使用,公司已订阅))
{
ApplyDiscount(成本,公司认购);

因为:EligibleForDiscount!=EligibleForDiscount加上一个“i”,只是一个输入错误。

这可能是因为两个原因:

调用函数名时拼写错误:if(EligibleForDiscount(CompanyUsed,CompanySubscribed))应该像函数的实现一样编写,即EligibleForDiscount

如果您忘记声明函数的原型(该原型是您将要使用该函数的程序的指示器),则可能会发生这种情况。在使用函数bool EligibileForDiscount(const char,const char)之前,您只需在某个地方编写


其中一个应该可以工作!

p.s.您可以这样编写
EligibleFordScont

bool EligibileForDiscount(const char CompanyUsed, const char CompanySubscribed)
{

bool eligible = false;
    if (CompanyUsed==CompanySubscribed)
            eligible = true;

 return (eligible);

 }
bool EligibleForDiscount(const char CompanyUsed, const char CompanySubscribed)
{
 return CompanyUsed==CompanySubscribed;
}

它是在标题中声明的,而您忘记了包含它吗?我怀疑问题是输入错误。您最初将函数命名为
EligibleForDiscount()
,与您所称的
EligibleForDiscount()相差一个字母
。请注意,函数中混乱的代码可以减少为
return CompanyUsed==CompanySubscribed;
最好更改函数名以匹配正确的拼写,而不是更改函数调用以匹配拼写错误的名称。哦,哈哈,是的,这只是拼写错误的合格名称。谢谢谢谢你指出这一点。