到另一个程序。这是一个模拟银行账户的程序。我需要帮助显示余额,提款和存款。如何在取款/存款后显示最终余额?
#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;
}
答案 0 :(得分:3)
cout << "balance for " << name () << " is " << balance()
<<endl;
通过在它们后面添加括号,您尝试调用name
和balance
类似函数,但它们是string
。删除括号。
更重要的是,是什么让你认为必须在那里包括括号?可能有一个C ++的基本部分,你应该寻求完全理解(功能)。
答案 1 :(得分:1)
您尝试在此处调用name
和balance
作为函数:
cout << "balance for " << name () << " is " << balance() <<endl;
^^^^^^^ ^^^^^^^^^
但name
是string
而balance
是double
。此编辑将解决问题:
cout << "balance for " << name << " is " << balance <<endl;