感谢所有快速回复。他们都真的有帮助。
大家好,我是 C# 和强类型语言的新手。
我正在尝试从我的 WithdrawAmount 方法返回 int 金额,以便我可以将其用作 DispenseCash cash 方法中的参数。我收到错误“当前上下文中不存在名称‘金额’”。
我做错了什么,如果不是太麻烦,我可以被引导到在线资源以了解有关该问题的更多信息。谢谢 :)。
int whichAccount = int.Parse(Console.ReadLine());
do
{
WithdrawAmount(whichAccount);
DispenseCash(amount, whichAccount, invalidAmount);
} while (invalidAmount == true);
// end of little example segment of Main
static int WithdrawAmount(int whichAccount)
{
Console.Write("\nPlease enter how much you would like to withdraw: $");
int amount = int.Parse(Console.ReadLine());
return amount;
}//end WithdrawAmount
private static bool DispenseCash(int amount, int whichAccount, bool invalidAmount)
{
int numOf20s;
int numOf50s;
if (amount % 20 == 0)
{
numOf20s = amount / 20;
Console.WriteLine("Number of 20's = {0}", numOf20s);
accountBalances[whichAccount] = (accountBalances[whichAccount]) - amount;
return invalidAmount == false;
}
else if (amount % 50 == 0)
{
numOf50s = amount / 50;
Console.WriteLine("Number of 50's = {0}", numOf50s);
return invalidAmount == false;
}
else if ((amount - 50) % 20 == 0)
{
numOf50s = 1;
numOf20s = (amount - 50) / 20;
Console.WriteLine("Number of 20's = {0}", numOf20s);
Console.WriteLine("Number of 50's = {0}", numOf50s);
return invalidAmount == false;
}
else
{
Console.WriteLine("Invalid entry");
return invalidAmount == true;
}
}//end DispenseCash