感谢您的所有快速响应。他们都很有帮助。从一种方法返回int以在另一种方法中使用
大家好我是C#和强类型语言的新手。
我想从我的WithdrawAmount方法返回int数量,以便我可以在DispenseCash现金方法中使用它作为参数。我收到错误“名称数量”在当前上下文中不存在“。
我在做什么错,如果没有太多的麻烦,我可以指示在线资源了解更多的问题。谢谢 :)。
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
有什么用这条线INT whichAccount = int.Parse的(到Console.ReadLine()); – Kalyan
这样用户可以选择他们想要退出的银行账户。 – user2281248
好的。您正在将whichAccount传递给WithdrawAmount()方法。但是你没有使用该方法中的哪个帐户。 – Kalyan