IntelliSense:函数调用中的参数太少
IntelliSense: too few arguments in function call
我正在为一个类编写一个程序,该类获取销售额并计算美元的变化。每个面额都以硬币数量作为输出列出。由于参数太少的错误,我无法运行它?
我不确定VB在这里找什么。如有任何帮助,我们将不胜感激。
程序代码:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
using namespace std;
// Determines how many of each coin to dispense.
void Dispenser(int, int *, int *, int *, int *);
int main(void)
{
// Change the console's background color.
system ("color F0");
// Declares the variables.
double amount_paid = 1.00, amount_due;
int amount_left, dollar_qty, quarter_qty, dime_qty, nickel_qty, penny_qty;
// Get user input.
cout << "n";
cout << "Enter the money amount paid: $";
cin >> amount_due;
cin.ignore();
// Perform calculations.
amount_paid = amount_paid * 100 + 0.5;
amount_due = amount_due * 100;
amount_left = amount_paid - amount_due;
dollar_qty = amount_left / 100;
Dispenser (amount_left + quarter_qty + dime_qty + nickel_qty + penny_qty);
"n";
// Display output.
cout << "nAmount of the purchase: " << fixed << setprecision(2) << showpoint << amount_due;
cout << "nChange from $1.00: " << fixed << setprecision(2) << showpoint << amount_left;
cout << "n" << fixed << setprecision(2) << showpoint << dollar_qty << " dollars";
cout << "n" << fixed << setprecision(2) << showpoint << quarter_qty << "quarters";
cout << "n" << fixed << setprecision(2) << showpoint << dime_qty << "dimes";
cout << "n" << fixed << setprecision(2) << showpoint << nickel_qty << "nickles";
cout << "n" << fixed << setprecision(2) << showpoint << penny_qty << "pennies";
system("pause");
return 0;
}
void Dispenser(int amt_left, int *quarters, int *dimes, int *nickels, int *pennies)
{
int total_change, total_quarters, total_dimes, total_nickels, total_pennies;
// Determine change amount by quantity.
total_change = amt_left % 100;
total_quarters = total_change / 25;
total_change = total_change % 25;
total_dimes = total_change / 10;
total_change = total_change % 10;
total_nickels = total_change / 5;
total_change = total_change % 5;
total_pennies = total_change;
*quarters = total_quarters;
*dimes = total_dimes;
*nickels = total_nickels;
*pennies = total_pennies;
}
错误出现在"("的这一行
Dispenser (amount_left + quarter_qty + dime_qty + nickel_qty + penny_qty);
Dispenser (amount_left + quarter_qty + dime_qty + nickel_qty + penny_qty);
应该是
Dispenser (amount_left, quarter_qty, dime_qty, nickel_qty, penny_qty);
您的版本实际上只是一个将所有值相加的大参数,而我提供的带有逗号的版本意味着它是5个单独的参数发送到函数。
Dispenser (amount_left + quarter_qty + dime_qty + nickel_qty + penny_qty);
应该是
Dispenser (amount_left, &quarter_qty, &dime_qty, &nickel_qty, &penny_qty);
您使用了'+'而不是','?
相关文章:
- 函数调用中参数的顺序重要吗
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 如何用参数值调用函数(仅在运行时已知)
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 函数调用C++中的参数太少
- 将参数打包的参数传递到 std::queue 中,以便稍后使用不同的函数调用
- 根据参数数调用 mixin 基类的构造函数
- 使用并行参数向量调用元素向量的成员函数
- uncrustify:如何将多行 C 函数调用的参数组合到一行上?
- 函数调用中的参数过多
- 使用显式模板参数列表和 [temp.arg.explicit]/3 的函数调用的演绎失败
- 可变参数模板函数:调用没有匹配函数,std::endl
- 对可变参数函数的递归调用的链接器错误
- 宏函数调用缺少参数警告,即使给定了参数
- 具有不同类型的可选参数的调用方函数
- C++ 使函数调用依赖于模板参数
- 迭代器的模板参数:函数在调用时推断类型?
- 如果我提前将参数声明为变量而不是将它们内联写入函数调用,那有什么区别(在内存方面)?
- 链接可变参数函数调用
- 递归可变参数函数调用对简单 if.else 语句的性能