0
我正在嘗試將X天數的便士數量加倍。付出的便士 - 數學計算 - C#
因此,3天= 4個便士,4天= 8個便士,等
我卡上得到正確的代碼放在:(我知道我很接近,我知道我失去了一些東西我已經花了5個小時在這,我只是想看到解決方案,所以我的頭腦會把它放在一起,它是如何工作的...)
我終於明白了...現在...怎麼可以我清理了這個?我還在學習中較少的代碼寫的...但我正在關注的起步W/Visual C#中的書現在...
// Local variables./
int daysWorkedInputValue;
decimal currentPayRate, newPayRate, totalPaySalary;
int daysWorked;
int count = 0;
currentPayRate = 0.01m;
totalPaySalary = 0m;
daysWorkedInputValue = int.Parse(daysWorkedInputTextBox.Text);
if (int.TryParse(daysWorkedInputTextBox.Text, out daysWorked))
{
if (daysWorked >= 0)
{
// Continue to process the input./
if (daysWorkedInputValue == 0)
{
totalPayCalcLabel.Text = "$0.00";
}
if (daysWorkedInputValue == 1)
{
totalPayCalcLabel.Text = "$0.01";
}
// The following loop calculates the total pay./
while (count <= (daysWorked - 1))
{
// Calculate the total pay amount./
if (count == 1)
{
currentPayRate = 0.01m;
totalPayCalcLabel.Text = currentPayRate.ToString("c");
}
currentPayRate = currentPayRate * 2;
totalPaySalary = currentPayRate;
if (count >= 1)
{
totalPayCalcLabel.Text = totalPaySalary.ToString("c");
}
// Add one to the loop counter./
count = count + 1;
// Return focus back to the organisms TextBox./
daysWorkedInputTextBox.Focus();
}
看起來是GP,它是幾何級數(https://en.wikipedia.org/wiki/Geometric_progression)? – Agalo
請分享問題背景的完整代碼。你沒有增加計數,還有其他的東西(沒有休息,沒有currentPay的重新分配) – Typist