我正在为一个课程编写程序,该课程需要一笔销售金额并计算一美元的变化。列出每种面额,以硬币数量作为输出。由于参数太少而导致错误,我无法运行它?
我不确定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);
答案 0 :(得分:5)
Dispenser (amount_left + quarter_qty + dime_qty + nickel_qty + penny_qty);
应该是
Dispenser (amount_left, quarter_qty, dime_qty, nickel_qty, penny_qty);
你的版本实际上只是一个大的参数,加起来所有的值,而我提供的那个,用逗号,意味着它是5个独立的参数发送到函数。
答案 1 :(得分:2)
您使用了'+'代替','?
答案 2 :(得分:2)
Dispenser (amount_left + quarter_qty + dime_qty + nickel_qty + penny_qty);
应该是
Dispenser (amount_left, &quarter_qty, &dime_qty, &nickel_qty, &penny_qty);