我创建了一个函数来确定cableBoxFeesTotal
的值,然后我将它返回给本地变量cableBoxFeesTotal
。当我尝试在函数外部使用cableBoxFeesTotal
的值时,值为0.00,而不是函数返回的值。我一直在为此工作好几天,似乎无法弄清楚我做错了什么。请告诉我如何解决这个问题。谢谢!我的函数不会将值返回给C++中的本地变量
我不想发布整个代码..这是作业,但我没有添加下面的两个部分。
#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>
#include <cmath>
using namespace std;
const double BASIC_CABLE = 43.00;
const double PREMIUM_CABLE = 58.00;
const double BASIC_BOX = 7.50;
const double PREMIUM_BOX = 11.25;
const double PREMIUM_CHANNEL_FEE = 9.99;
const double EMPLOYEE_DISCOUNT_AMOUNT = .14;
double feeFunction (int cableBoxes, double serviceLevel, double cableBoxFeesTotal, double BASIC_BOX, double PREMIUM_BOX, char B, char P)
{
if (cableBoxes > 2 && serviceLevel == 'B')
{
cableBoxFeesTotal = ((cableBoxes - 2) * BASIC_BOX);
cout << "Cable Box Fees: " << setw(15) << cableBoxFeesTotal << endl;
}
else if (cableBoxes > 2 && serviceLevel == 'P')
{
cableBoxFeesTotal = ((cableBoxes - 2) * PREMIUM_BOX);
cout << "Cable Box Fees: " << setw(15) << cableBoxFeesTotal << endl;
}
return (cableBoxFeesTotal);
}
int main()
{
string employee;
bool hasPremium;
char H;
char B;
char P;
char premiumChannel;
char serviceLevel;
int cableBoxes = 0 ;
double customerID;
double monthlyRateTotal = 0.00;
double cableBoxFeesTotal = 0.00;
double premiumChannelTotal = 0.00;
double subtotal = 0.00;`enter code here`
double employeeDiscount = 0.00;
double total = 0.00;
feeFunction (cableBoxes, serviceLevel, cableBoxFeesTotal, BASIC_BOX, PREMIUM_BOX, B, P);
cout << cableBoxFeesTotal << endl;
if (hasPremium == true)
{
subtotal = (cableBoxFeesTotal + monthlyRateTotal + PREMIUM_CHANNEL_FEE);
cout << "Subtotal:" << setw(15) << subtotal << endl;
}
else if (hasPremium == false)
{
subtotal = (monthlyRateTotal + cableBoxFeesTotal);
cout << "Subtotal:" << setw(15) << subtotal << endl;
}
}
您的代码段似乎损坏了...... – 2011-05-29 14:10:26
显然,您在代码中缺少对函数“feeFunction”的函数调用。 – cpx 2011-05-29 14:15:18
这是功课吗?如果是这样,请标记为这样。 – 2011-05-29 14:17:00