我正在寻找将什么放入 purse.CountMoney(); 的参数中 如果有的话...我有一个心理障碍,因为与非返回方法相比,返回值的方法如何工作...我尝试了总计...双倍总计....嗯,我尝试进入程序,看看是否调试工具可以提供帮助,但我没有任何反应。
任何指导都很棒。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lab24
{
class Program
{
static void Main()
{
CoinPurse purse = new CoinPurse();
purse.AddPenny(3);
purse.AddNickel(4);
purse.AddDime(2);
purse.AddQuarter(1);
purse.CountMoney();
purse.TakeNickels(4);
purse.CountMoney();
Console.ReadLine();
}
public class CoinPurse
{
private int numPennies;
private int numNickels;
private int numDimes;
private int numQuarters;
private double total;
public CoinPurse()
{
numPennies = 0;
numNickels = 0;
numDimes = 0;
numQuarters = 0;
total = 0;
}
public void AddPenny(int p)
{
numPennies += p;
}
public void AddNickel(int n)
{
numNickels += n;
}
public void AddDime(int d)
{
numDimes += d;
}
public void AddQuarter(int q)
{
numQuarters += q;
}
public void TakePenny(int p)
{
numPennies -= p;
}
public void TakeNickels(int n)
{
numNickels -= n;
}
public void TakeDime(int d)
{
numDimes -= d;
}
public void TakeQuarters(int q)
{
numQuarters -= q;
}
public double CountMoney(double total)
{
double q = numQuarters * .25;
double d = numDimes * .10;
double n = numNickels * .05;
double p = numPennies * .01;
total = q + d + n + p;
return total;
}
}
}
}