Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

       public void Calculate()
         {
             if (txtTaxPer.Text != "")
             {
                 txtTaxAmt.Text = Convert.ToInt32((Convert.ToInt32(txtSubTotal.Text) * Convert.ToDouble(txtTaxPer.Text) / 100)).ToString();

             }
             if (txtDiscountPer.Text != "")
             {
                 txtDiscountAmount.Text = Convert.ToInt32(((Convert.ToInt32(txtSubTotal.Text) + Convert.ToInt32(txtTaxAmt.Text)) * Convert.ToDouble(txtDiscountPer.Text) / 100)).ToString();
             }
             int val1 = 0;
             int val2 = 0;
             int val3 = 0;
             int val4 = 0;
             int val5= 0;
             int.TryParse(txtTaxAmt.Text, out val1);
             int.TryParse(txtSubTotal.Text, out val2);
             int.TryParse(txtDiscountAmount.Text, out val3);
             int.TryParse(txtTotal.Text, out val4);
             int.TryParse(txtTotalPayment.Text, out val5);
             val4 = val1 + val2 - val3;
             txtTotal.Text = val4.ToString();
             int I = (val4 - val5);
             txtPaymentDue.Text = I.ToString();


         }