关于函数调用,我的程序没有读取我的其他函数。为什么?
Regarding function calls, my program isn't reading my other functions. Why?
using namespace std;
int amount_total(int amount_paid, int& amountleft), quarters(int&
amountleft), dimes(int& amountleft), pennies(int& amountleft);
int amount_total(int amount_paid, int& amountleft)
{
const int TOTALVALUE = 99;
cout << "You have bought a candy bar that's 99 cents. n"
<< "Please insert the amount paid. " << endl;
cin >> amount_paid;
amountleft = TOTALVALUE - amount_paid;
cout << "You have to pay : " << amountleft << " cents. n" << endl;
return(0);
}
int quarters(int& amountleft)
{
const int QUARTERS = 25;
int total, count_Quarters;
count_Quarters = 0;
while (amountleft > 0 || amountleft >= QUARTERS)
{
total = amountleft - QUARTERS;
count_Quarters++;
}
return(count_Quarters);
}
int dimes(int& amountleft)
{
const int DIMES = 10, QUARTERS = 25;
int total, count_Dimes;
count_Dimes = 0;
while (amountleft > 0 || amountleft <= QUARTERS)
{
total = amountleft - DIMES;
count_Dimes++;
}
return(count_Dimes);
}
int pennies(int& amountleft)
{
const int PENNIES = 1, DIMES = 10;
int total, count_Pennies;
count_Pennies = 0;
while (amountleft >= 0 || amountleft <= DIMES)
{
total = amountleft - PENNIES;
count_Pennies++;
}
return(count_Pennies);
}
int main()
{
int amount_paid, amountleft, Count_Quarters,
Count_Dimes, Count_Pennies, total_amount;
total_amount = amount_total(amount_paid, amountleft);
Count_Quarters = quarters(amountleft);
Count_Dimes = dimes(amountleft);
Count_Pennies = pennies(amountleft);
cout << "You'll get : " << Count_Quarters << " quarters, " <<
Count_Dimes << " dimes, and " << Count_Pennies << " pennies. n"
<< endl;
return 0;
}
//样品运行:
你买了一块99美分的巧克力棒。请插入已支付的金额。36你必须支付:63美分。
我最初的计划是让程序运行,main只运行函数,函数会返回变量,但它没有这样做,它只运行第一个函数
21 int quarters( int& amountleft ) {
22 const int QUARTERS = 25;
23 int total, count_Quarters;
24 count_Quarters = 0;
25 cout << "before while-loop" << endl;
26 while( amountleft > 0 || amountleft >= QUARTERS ) {
27 cout << "count_Quarters = " << count_Quarters << endl;
28 cout << "amountleft = " << amountleft << endl;
29 total = amountleft - QUARTERS;
30
31 count_Quarters++;
32 }
33 cout << "after while-loop" << endl;
34 return count_Quarters;
35 }
请记住,由于您还没有定义"total"变量,它可以包含任何垃圾,但通常不会。无论如何,在使用变量之前,将任何值(例如0)分配给变量是很好的。
相关文章:
- 为什么在我的函数类型后使用引用运算符 (&) 允许我修改它返回的值?
- 在哪里放置我的函数?进入我的母语 Gui 还是进入我的演示者?
- 查找定义我的 C/C++ 函数/宏的文件比'grep'更简单的方法
- 为什么我的 constexpr 对象在我的函数中不是 constexpr?
- 为什么我的函数接受"std::string"进行排序不会改变它?
- 为什么 emscripten 不编译我的函数?
- binary_search() 函数在我的函数体中不起作用
- 如何将不同大小的数组传递给我的 C++ 函数?
- 如果我想使用 cout 为我的函数提供任何输入......我该如何给出
- (C++)我的函数不返回数组
- 如何让我的重载<<运算符打印出我的函数?
- 我的函数调用 (C++) 中的未声明标识符
- 钩/绕道 d3d9 (现在/结束场景) - 似乎调用我的函数然后崩溃
- 成员函数的"this"参数具有"const"类型,但我的函数实际上不是"const"
- 我应该声明我的函数模板专业化还是定义它们就足够了
- 为什么我的函数名称中会随机出现一个额外的字母
- 为什么我的函数无法使用指针打印多维数组的元素?
- 当我从头文件和实现文件调用我的函数到我的主文件时,我没有得到任何输出
- 钩子SSDT.其他驱动程序使用我的函数
- 如何修复我的函数 popFront 为我的列表?