Home > Software design >  How do I pass the compute bonus to bonus formatted so it displays the number?
How do I pass the compute bonus to bonus formatted so it displays the number?

Time:10-30

namespace GreenvilleRevenueGUI
{
    public partial class Form1 : Form
    {
        const double BONUS1 = 50.00;
        const double BONUS2 = 75.00;
        const double BONUS3 = 100.00;
        const double BONUS4 = 200.00;

        double ProductivityScore = 0;
        double bonus = 0;

        private void Button1_Click(object sender, EventArgs e)
        {
            String bonusFormatted = "";
            String EmployeeName = EmployeeNametextBox.Text;
            double Numberofshifts = Double.Parse(NumberoFShiftstextBox.Text);
            double NumberofTranactions = Double.Parse(NumTransactionstextBox.Text);
            double totalValue = Double.Parse(TotalValuetextBox.Text);
            ProductivityScore = totalValue / NumberofTranactions / Numberofshifts;

            computeBonus();

            String msgOutput = EmployeeName   "\nYour Productivity Score is: "   ProductivityScore;
            msgOutput = msgOutput   "\nYour Bonus is: "   bonusFormatted   "$";
            MessageBox.Show(msgOutput, "Employee Bonus ");
        }

        private double computeBonus()
        {
            double thebonus = 0;
            if (ProductivityScore <= 30)
            {
                thebonus = BONUS1;
            }
            else if (30 < ProductivityScore && ProductivityScore < 70)
            {
                thebonus = BONUS2;

            }
            else if (70 <= ProductivityScore && ProductivityScore < 200)
            {
                thebonus = BONUS3;

            }
            else if (ProductivityScore >= 200)
            {
                thebonus = BONUS4;

            }
            return thebonus;
        }
    }
}

ive tried to parse thebonus to bonus but so I can put it into a text feild but thebonus only exists in the in the private doubble so I made a stringe called bonus formated I think that has to do with part of the solution I just dont know what to do from here.

specifically what I am trying to do is take thebonus and have it displayed here msgOutput = msgOutput "\nYour Bonus is: " bonusFormatted "$"; I want it displayed where bonusFormatted is located i just cant figure out how to do so

CodePudding user response:

I'm not sure if this what you want to do, but you can save the result of ComputeBonus function into a variable called bonus, and then use .ToString() method to convert the bonus into a string so you can use it inside the message.

namespace GreenvilleRevenueGUI
{
    public partial class Form1 : Form
    {
        const double BONUS1 = 50.00;
        const double BONUS2 = 75.00;
        const double BONUS3 = 100.00;
        const double BONUS4 = 200.00;

        double ProductivityScore = 0;
        double bonus = 0;

        private void Button1_Click(object sender, EventArgs e)
        {
            String bonusFormatted = "";
            String EmployeeName = EmployeeNametextBox.Text;
            double Numberofshifts = Double.Parse(NumberoFShiftstextBox.Text);
            double NumberofTranactions = Double.Parse(NumTransactionstextBox.Text);
            double totalValue = Double.Parse(TotalValuetextBox.Text);
            ProductivityScore = totalValue / NumberofTranactions / Numberofshifts;

            var bonus = computeBonus();

            String msgOutput = EmployeeName   "\nYour Productivity Score is: "   ProductivityScore;
            msgOutput = msgOutput   "\nYour Bonus is: "   bonus.ToString()   "$";
            MessageBox.Show(msgOutput, "Employee Bonus ");
        }

        private double computeBonus()
        {
            double thebonus = 0;
            if (ProductivityScore <= 30)
            {
                thebonus = BONUS1;
            }
            else if (30 < ProductivityScore && ProductivityScore < 70)
            {
                thebonus = BONUS2;

            }
            else if (70 <= ProductivityScore && ProductivityScore < 200)
            {
                thebonus = BONUS3;

            }
            else if (ProductivityScore >= 200)
            {
                thebonus = BONUS4;

            }
            return thebonus;
        }
    }
}
  •  Tags:  
  • c#
  • Related