Percentage Calculation in C#

  1. public void CalculateTotal()   
  2. {  
  3.     int th1, th2, practical, oral, termwork, total;  
  4.     double percentage;  
  5.   
  6.     th1 = Convert.ToInt32(txtTheory1.Text);  
  7.     th2 = Convert.ToInt32(txtTheory2.Text);  
  8.     practical = Convert.ToInt32(txtPractical.Text);  
  9.     oral = Convert.ToInt32(txtOral.Text);  
  10.     termwork = Convert.ToInt32(txtTermWork.Text);  
  11.   
  12.     total = th1 + th2 + practical + oral + termwork;  
  13.     txtTotal.Text = total.ToString();  
  14.   
  15.     if (Convert.ToInt32(txtTheory2.Text) == 0)   
  16.     {  
  17.         percentage = total * 100 f / 300;  
  18.         txtPercent.Text = Math.Round(percentage, 2).ToString() + " %";  
  19.     }  
  20. }