1

how to make every time the gpa equal to 3.5 to 4.0 there message pop and next form. i manage to do but when the gpa is below 3.5 the message still appear but i did change the int to string. idk is it because i change to string

public partial class Form1 : Form
     {
         public static string passingtext;
         String lettergrd;
         double credit;
         double caltimes = 0;
         double totalcal = 0;
         double totalcredit = 0;
         double finalgpa = 0;
         double A = 4.0;
         double AMINUS = 3.67;
         double BPLUS = 3.33;
         double B = 3.0;
         double BMINUS = 2.67;
         double CPLUS = 2.33;
         double C = 2.0;
         double CMINUS = 1.67;
         double D = 1.00;
         double F = 0.0;
         ComboBox defaultcombo = new ComboBox();
         NumericUpDown defaultnumeric = new NumericUpDown();

         public Form1()
         {
             InitializeComponent();
         }

         private void Form1_Load(object sender, EventArgs e)
         {

         }

         private void btncalculateGPA_Click(object sender, EventArgs e)
         {



             lettergrd = "";
             credit = 0;
             caltimes = 0;
             totalcal = 0;
             totalcredit = 0;
             finalgpa = 0;
             defaultcombo = new ComboBox();
             defaultnumeric = new NumericUpDown();
             for (int i = 0; i < 7; i++)
             {

                 switch (i)
                 {
                     case 0:
                         defaultcombo = cmbCourse1;
                         defaultnumeric = numCourse1;
                         break;
                     case 1:
                         defaultcombo = cmbCourse2;
                         defaultnumeric = numCourse2;
                         break;
                     case 2:
                         defaultcombo = cmbCourse3;
                         defaultnumeric = numCourse3;
                         break;
                     case 3:
                         defaultcombo = cmbCourse4;
                         defaultnumeric = numCourse4;
                         break;
                     case 4:
                         defaultcombo = cmbCourse5;
                         defaultnumeric = numCourse5;
                         break;
                     case 5:
                         defaultcombo = cmbCourse6;
                         defaultnumeric = numCourse6;
                         break;
                     case 6:
                         defaultcombo = cmbCourse7;
                         defaultnumeric = numCourse7;
                         break;
                 }

                 lettergrd = defaultcombo.Text;
                 credit = Double.Parse(defaultnumeric.Value.ToString());


                 if (lettergrd != String.Empty && credit != 0)
                 {

                     switch (lettergrd)
                     {
                         case "A":
                             caltimes = credit * A;
                             break;
                         case "A-":
                             caltimes = credit * AMINUS;
                             break;
                         case "B+":
                             caltimes = credit * BPLUS;
                             break;
                         case "B":
                             caltimes = credit * B;
                             break;
                         case "B-":
                             caltimes = credit * BMINUS;
                             break;
                         case "C+":
                             caltimes = credit * CPLUS;
                             break;
                         case "C":
                             caltimes = credit * C;
                             break;
                         case "C-":
                             caltimes = credit * CMINUS;
                             break;
                         case "D":
                             caltimes = credit * D;
                             break;
                         case "F":
                             caltimes = credit * F;
                             break;

                     }

                     totalcredit = totalcredit + credit;
                     totalcal = totalcal + caltimes;
                 }

             }

             finalgpa = totalcal / totalcredit;

             lblgpa.Text = finalgpa.ToString("#.00");<-- this is after calculation of the gpa then the gpa will appear at lblgpa

             if (lblgpa.Text ==  "3.5") ;<--- this is im trying make when gpa is equal to 3,5  the message will appear. but gpa below 3.5 the message also 
             {
                 MessageBox.Show("Higher change go poly");

                 Form3 f3 = new Form3();
                 f3.ShowDialog();
             }

         }

         private void btnreset_Click(object sender, EventArgs e)
         {
             cmbCourse1.ResetText();
             cmbCourse2.ResetText();
             cmbCourse3.ResetText();
             cmbCourse4.ResetText();
             cmbCourse5.ResetText();
             cmbCourse6.ResetText();
             cmbCourse7.ResetText();

             numCourse1.ResetText();
             numCourse2.ResetText();
             numCourse3.ResetText();
             numCourse4.ResetText();
             numCourse5.ResetText();
             numCourse6.ResetText();
             numCourse7.ResetText();
         }

         private void button3_Click(object sender, EventArgs e)
         {
             this.Hide();
             passingtext = username.Text;
             Form2 f2 = new Form2();
                 f2.ShowDialog();
             this.Close();
         }

         private void label11_Click(object sender, EventArgs e)
         {

         }
     }
    }
001
  • 13,291
  • 5
  • 35
  • 66
  • `if (lblgpa.Text == "3.5") ;` The semi-colon should not be there. – 001 Oct 12 '18 at 18:59
  • Also, since you format the text with `finalgpa.ToString("#.00")` you need to compare to `"3.50"`. Of course, this won't handle any of the cases where the value is greater than 3.5. – 001 Oct 12 '18 at 19:03
  • Jonny mopp can tell me more how to compare the course? – Zykov Leonid Oct 12 '18 at 19:11
  • Don't use the string, use the numerical value you calculated: `if (finalgpa >= 3.5)` – 001 Oct 12 '18 at 19:14
  • but i convert it to string blgpa.Text = finalgpa.ToString("#.00"); how can i convert back ? – Zykov Leonid Oct 12 '18 at 19:15
  • That doesn't change `finalgpa`. The `ToString` function returns a _new_ string. The original variable remains unchanged. You can't change a `double` to a `string`. You can only create a new `string` that is a textual representation of the `double`. – 001 Oct 12 '18 at 19:19

0 Answers0