编程题,可以帮我看下错在那里吗?
程序代码:
#include "stdafx.h" #include <iostream> using namespace std; class Yuebao { static double profitRate;//声明利息 double yue;//余额 public: static void setProfitRate(double rate); /* Your code here! */ Yuebao(double a):yue(a){}//构造函数 void addProfit() { yue+=yue*profitRate; } void deposit(double amountin) { yue += amountin; } void withdraw(double amountout) { yue-=amountout; } double getBalance() { return yue; } }; void Yuebao::setProfitRate(double rate) { //定义余额 profitRate = rate; } int main() { int n; while (cin >> n) { double profitRate; cin >> profitRate; Yuebao::setProfitRate(profitRate);//设定鱼额宝的利率 Yuebao y(0); //新建鱼额宝账户,余额初始化为0 int operation;//接受输入判断是存还是取 double amount;//接受输入存取金额 for (int i = 0; i < n; ++i) { y.addProfit();//加入前一天余额产生的利息 cin >> operation >> amount; if (operation == 0) y.deposit(amount);//存入金额 else y.withdraw(amount);//取出金额 } cout << y.getBalance() << endl;//输出最终账户余额 } return 0; }
生成后显示下面的错误,试了很久也没弄清楚怎么回事。