Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1.  
  2.  
  3. private void btnCalc_Click(object sender, EventArgs e)
  4.         {
  5.            // Take in Data from text box and convert to integer
  6.             int numCopies = Convert.ToInt32(txtCopies.Text);
  7.  
  8.            // Create two temp variables for math we need to do
  9.             double tempCost;
  10.             double tempCopies;
  11.  
  12.             if (numCopies <= 100)
  13.             {
  14.            //Calculate the cost if number of copies is less than 100
  15.                tempCost = numCopies * 0.1;
  16.  
  17.            //Output to text box and multiple by 23% to add vat
  18.                 txtIncVat.Text = Convert.ToString(tempCost * 1.23);
  19.             }
  20.             else if (numCopies <= 200)
  21.             {
  22.            //If its greater than 200 we know the first 100 will be charged at 10 cent we need to find how many will be at 6 cent. We must take the 100 from the number of copies to find the number left over. The left over is how many will be charged at 6 cent
  23.                 tempCopies = numCopies - 100;
  24.  
  25.            // We add the first 100 at 10 cent and then we take the remaining copies and charge them at 6 cent.
  26.                tempCost = (100 * 0.1) + tempCopies * 0.06;
  27.  
  28.           // Output the cost to the text box
  29.                 txtIncVat.Text = Convert.ToString(tempCost * 1.23);
  30.             }
  31.             else
  32.             {
  33.          // This time we take 200 because we know the first 100 at 10 cent and the second 100 at 6 cent we need the final remainder.
  34.                 tempCopies = numCopies - 200;
  35.  
  36.         //Then finally add the cost of the first 100 at 10 cent, the second 100 at 6 cent, then we get our remainder and multiply it by 4 cent.
  37.                 tempCost = (100 * 0.1) + (100 * 0.06) + tempCopies * 0.04;
  38.                 txtIncVat.Text = Convert.ToString(tempCost * 1.23);
  39.  
  40.             }
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement