2013-05-22 33 views
0

到另一個程序。這是一個模擬銀行賬戶的程序。我需要幫助顯示餘額,提取和存款。如何在退出/存款後顯示最終餘額?銀行賬戶計劃構建和入門的問題

#include <iostream> 
#include <string> 
#include "BACCOUNT.H" 

    using namespace std; 
    int main() 
    { 
     double amount = 0.0; 
     double withrdraw = 0.0; 
     double deposit = 0.0; 
     string name; 
     double startamount = 100.00; 
     double balance = 0.0; 


     cout << "name: "; 
     cin >> name; 

     cout << "initial balance: " << startamount <<endl; 


     cout << "deposit? "; 
     cin >> amount; 
     cout << "withdraw? "; 
     cin >> amount; 


     cout << "balance for " << name << " is " << balance << endl; 

     system ("pause"); 

     return 0; 
    } 

回答

3
cout << "balance for " << name() << " is " << balance() 
    <<endl; 

通過把括號後他們,你想打電話namebalance類似的功能,但他們string秒。刪除括號。

更重要的是,是什麼讓你認爲你不得不包括括號?可能存在一個基本的C++,你應該試圖完全理解你對(函數)的困惑。

+0

我剛剛更新了我的代碼上面...我如何得到它來計算最終平衡? –

+1

你告訴我!畢竟,這是你的任務。 –

+0

好的,謝謝@Jonathon Reinhart的幫助。 –

1

您嘗試呼叫namebalance如下功能:

cout << "balance for " << name() << " is " << balance() <<endl; 
          ^^^^^^^    ^^^^^^^^^ 

namestringbalancedouble。此編輯將解決問題:

cout << "balance for " << name << " is " << balance <<endl;