float deposit (float balance)
{
float amount[3];
system("cls");
cout<<"Enter the amount you wish to deposit"<<endl;
cin>>amount[3];
balance = balance + amount[3];
writeBalance(balance);
return balance;
}
//This is a function to allow the user to increase their balance
,但是当我在节目中的存款部分输入量的弹出框出现,并说:试图建立一个数组过去三年存款存入银行账户系统
Run-Time Check Failure #2 - Stack around the variable 'amount' was corrupted.
任何帮助将非常感谢
C++数组从零开始。金额[0],金额[1],金额[2]有效。 – Roddy
您只能访问金额[0],金额[1]和金额[2] – Hamza
关于使用浮点类型的金钱,即使是'double'(或'long double')也无济于事。任何算术计算(甚至微不足道)都会增加复合舍入误差,迟早(最可能更快)将导致严重问题。你可能想阅读[每个计算机科学家应该知道的关于浮点运算的知识](http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)。 –