2013-02-27 86 views
0

我正在爲需要銷售額並計算美元變化的類編寫一個程序。每種面額都以輸出的硬幣數量列出。由於參數太少而導致錯誤,我無法運行它?智能感知:功能調用中的參數太少

我不知道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); 

回答

2
Dispenser (amount_left + quarter_qty + dime_qty + nickel_qty + penny_qty); 

應該

Dispenser (amount_left, &quarter_qty, &dime_qty, &nickel_qty, &penny_qty); 
+0

這工作,謝謝!愚蠢的問題,爲什麼「&」? – 2013-02-27 20:46:01

+0

基本函數需要一個內存地址,並且將該地址發送給該函數,而不是該變量的值。 – Gyhth 2013-02-27 20:50:10

2

您使用 '+',而不是 ''?

5
Dispenser (amount_left + quarter_qty + dime_qty + nickel_qty + penny_qty); 

應該

Dispenser (amount_left, quarter_qty, dime_qty, nickel_qty, penny_qty); 

您的版本真的只是一個大的參數相加了所有的值,而我提供的一個,用逗號,意味着它是跨越發送到5個獨立的參數功能。