Запуск Всего C # - PullRequest
       37

Запуск Всего C #

0 голосов
/ 19 октября 2018

Я создаю приложение для пожертвований, которое читает входные данные в текстовом поле и преобразует их в двойные.Затем, используя метод operatingCost, нужно взять это преобразованное удвоение и разделить его на 17% (операционные сборы)В настоящее время в методе у меня есть переменная dontationBFees, входящая, а затем деленная на 17 и создающая новую переменную afterFees.Все работает нормально, но мне нужно создать промежуточный итог, который сэкономит все пожертвования.Он должен отображать общую сумму, собранную для благотворительной организации (то есть общую сумму пожертвований за вычетом всех операционных расходов) для всех пожертвований до этого момента.Я знаю, что мне нужен цикл while или цикл while, чтобы приложение работало и продолжало добавлять данные.Я просто не понимаю, почему этот код не производит промежуточный итог.Я ищу помощь.Есть что-то, что я пропускаю.

   private decimal donationBFees = 0;

    void deductOperatingCost(ref decimal afterFeesParam)
    {
        afterFeesParam = afterFeesParam - (afterFeesParam  / 100 * 17);
    }


    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Boolean set = true;
        do
        {

            String donationBeforeFees;
            decimal totalDonationRaised;

            donationBeforeFees = donationBox.Text;
            donationBFees = System.Convert.ToDecimal(donationBeforeFees);


            decimal afterFees = donationBFees;
            deductOperatingCost(ref afterFees);
            afterFeesBox.Text = afterFees.ToString("$###, ##0.00");

            //This is the for loop I'm using to get the running total
            for (int i = 0; i < afterFees; i++)
            {
                decimal total = 0;
                total += afterFees;
                totalDonationRaised = total;
                totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");
            }

        } while (set == false);
    }

}

}

Ответы [ 2 ]

0 голосов
/ 21 октября 2018

Я пытаюсь использовать этот метод для промежуточного итога, но с добавлением номера, когда я их удаляю.

    private decimal donationBFees = 0;
    private decimal total = 0;
    private decimal afterFees = 0;
    private decimal totalDonationRaised;

    void deductOperatingCost(ref decimal afterFeesParam)
    {
        afterFeesParam = afterFeesParam - (afterFeesParam  / 100 * 17);
    }

    void runningTotal(ref decimal runningTotalParam)
    {
        runningTotalParam = runningTotalParam + runningTotalParam;
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {


            String donationBeforeFees;


            donationBeforeFees = donationBox.Text;
            donationBFees = System.Convert.ToDecimal(donationBeforeFees);


            decimal afterFees = donationBFees;
            deductOperatingCost(ref afterFees);
            afterFeesBox.Text = afterFees.ToString("$###, ##0.00");

            total = afterFees;
            totalDonationRaised = total;
            totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");

    }

    private void donationBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        //total += afterFees;

        runningTotal(ref total);
        totalDonationRaised = total;
        totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");
    }

}
0 голосов
/ 20 октября 2018
    private decimal donationBFees = 0;
    private decimal total = 0;
    private decimal afterFees = 0;
    private decimal totalDonationRaised;

    void deductOperatingCost(ref decimal afterFeesParam)
    {
        afterFeesParam = afterFeesParam - (afterFeesParam  / 100 * 17);
    }



    private void Button_Click(object sender, RoutedEventArgs e)
    {


            String donationBeforeFees;


            donationBeforeFees = donationBox.Text;
            donationBFees = System.Convert.ToDecimal(donationBeforeFees);


            decimal afterFees = donationBFees;
            deductOperatingCost(ref afterFees);
            afterFeesBox.Text = afterFees.ToString("$###, ##0.00");

            total = afterFees;
            totalDonationRaised = total;
            totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");

    }

    private void donationBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        total += afterFees;
        totalDonationRaised = total;
        totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");
    }
}
...