社区提示计算器问题

时间:2015-10-19 07:54:41

标签: c#

因此。我一直在为当地企业开发小费计算器,而且我遇到了一些问题。

它应该首先占总提示的10%并从总提示量中减去(对于关闭商店的人来说这是一个额外奖励),取剩余提示金额并将其除以给予前工人65%和后工人然后35%接受正在关闭的前线工人的数量,将正在关闭的前工人和正在关闭的后工人分成10%,并按照前面提到的(65%或35%)给他们各自的金额。分成10%,然后将总数吐出各自的盒子。

它没有吐出金额。我已经在纸上多次写出了这些方程式并实现了它们,但不知何故它们都在点击。

private void calcButton_Click(object sender, EventArgs e)
{
    //define objects
    double tipAmount;
    double tipReduction;
    double tipDeduction;
    double frontWorkers;
    double backWorkers;
    double closeFrontWorkers;
    double closeBackWorkers;
    double frontWorkersUse;
    double backWorkersUse;
    double closeFrontWorkersUse;
    double closeBackWorkersUse;
    double frontPer;
    double backPer;
    double closeFrontPer;
    double closeBackPer;
    double tipDeductionPer;
    double totalCloseWorkers;
    double frontWorkersNew;
    double backWorkersNew;

    tipAmount = double.Parse(tipBox.Text);
    frontWorkers = double.Parse(frontWorkBox.Text);
    backWorkers = double.Parse(backWorkBox.Text);
    closeFrontWorkers = double.Parse(frontCloseWorkBox.Text);
    closeBackWorkers = double.Parse(backCloseWorkBox.Text);
    frontWorkersNew = frontWorkers + closeFrontWorkers;
    backWorkersNew = backWorkers + closeBackWorkers;

    tipReduction = tipAmount * .9;
    tipDeduction = tipAmount - tipReduction;
    totalCloseWorkers = closeFrontWorkers + closeBackWorkers;
    tipDeductionPer = tipDeduction / totalCloseWorkers;

    frontWorkersUse = tipReduction * .65;
    backWorkersUse = tipReduction * .35;
    closeFrontWorkersUse = (frontWorkersUse/frontWorkersNew);
    closeBackWorkersUse = (backWorkersUse/backWorkersNew);

    frontPer = frontWorkersUse / frontWorkersNew;
    backPer = backWorkersUse / backWorkersNew;
    closeFrontPer = (closeFrontWorkersUse / closeFrontWorkers) + tipDeduction;
    closeBackPer = (closeBackWorkersUse / closeBackWorkers) + tipDeduction;


    totalFrontWorkBox.Text = String.Format("{0:c}", frontPer);
    totalBackWorkBox.Text = String.Format("{0:c}", backPer);
    totalCloseWorkBoxFront.Text = String.Format("{0:c}", closeFrontPer);
    totalCloseWorkBoxBack.Text = String.Format("{0:c}", closeBackPer);
}

1 个答案:

答案 0 :(得分:0)

嗯,你的(主要)问题在于逻辑。

我将您的代码复制到Linqpad并进行了更改,以便它不依赖于文本框。然后我用一些简单的值代替你的数字,并与我期望的相比较。这表明您的错误与关闭工人的小费计算有关,而不是一般提示。关闭工人的提示太大了!

然后,我查看了代码的相关部分,并想知道为什么要分配变量tipDeductionPer,但从不使用它的值 - 您正在使用tipDeduction并给每个关闭人员全额!

评论中其他人都说的也是有效的。您的代码可以更清晰,更容易理解,并且您会发现更容易发现错误。一旦修复了bug,就可以在Code Review上发帖,以获得有关如何改进它的一些指示。