用C++写存款方法,遇到麻烦
Writing a deposit method in C++, Having trouble
我正在编写一个方法,它接受要存入的金额的值作为参数。如果金额大于 bal(余额),帐户将更新为新金额。否则它 returns 旧的 bal 并退出。这是我的代码:
double withdraw(double amount)
{
if((bal-amount)<0)
{
throw new Exception
("There were insufficient funds");
else
bal=bal-amount;
return bal;
}
}
我在处理 Exception 和 else 语句时遇到错误。
您把 { }
放错了地方。
double withdraw(double amount)
{
if((bal-amount)<0)
{
throw new Exception("There were insufficient funds");
}
else
{
bal=bal-amount;
}
return bal;
}
我正在编写一个方法,它接受要存入的金额的值作为参数。如果金额大于 bal(余额),帐户将更新为新金额。否则它 returns 旧的 bal 并退出。这是我的代码:
double withdraw(double amount)
{
if((bal-amount)<0)
{
throw new Exception
("There were insufficient funds");
else
bal=bal-amount;
return bal;
}
}
我在处理 Exception 和 else 语句时遇到错误。
您把 { }
放错了地方。
double withdraw(double amount)
{
if((bal-amount)<0)
{
throw new Exception("There were insufficient funds");
}
else
{
bal=bal-amount;
}
return bal;
}