CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Dec 2011
    Posts
    6

    C# can't figure out whats going wrong

    I've been working on a project for school it's to calculate the GPA of the user and there CGPA based on the courses they've entered. I've been struggling with a minor problem that for some stupid reason i can't fix. Every time I add to the list box the GPA value always comes out as 0, I'm trying to get it so when the user adds the course to the listbox that it output the proper GPA as i've written in the GPA calculate class. If someone would briefly look at the code and give me a push in the right direction that would be great.
    Code:
           public void btnAdd_Click(object sender, EventArgs e)
            {
                //DECLARATIONS
                int hours;
                int grade;
                double GPA = 0;
                int CGPA;
                string courseName;
    
                try
                {
                    IsValidData();
    
                    grade = Convert.ToInt32(txtGrade.Text);
                    hours = Convert.ToInt32(txtHours.Text);
    
                    GPA = this.GPA_Calculate(grade, GPA);
    
                    lstGrades.Items.Add(txtCourseName.Text + "\t\t" + hours + "\t" + grade + "\t" + GPA);
                }
                catch
                {
                   
                }
    
            }
    
            public double GPA_Calculate(int grade, double GPA)
            {
    
                if (grade > 50)
                {
                    GPA = 0.0;
                }
                else if (grade <= 50 && grade >= 54)
                {
                    GPA = 1.0;
                }
                else if (grade <= 54 && grade >= 59)
                {
                    GPA = 1.5;
                }
                else if (grade <= 59 && grade >= 64)
                {
                    GPA = 2.0;
                }
                else if (grade <= 64 && grade >= 69)
                {
                    GPA = 2.5;
                }
                else if (grade <= 69 && grade >= 74)
                {
                    GPA = 3.0;
                }
                else if (grade <= 74 && grade >= 79)
                {
                    GPA = 3.5;
                }
                else if (grade <= 79 && grade >= 84)
                {
                    GPA = 4.0;
                }
                else if (grade <= 84 && grade >= 89)
                {
                    GPA = 4.5;
                }
                else if (grade <= 90 && grade >= 100)
                {
                    GPA = 5.0;
                }
                return GPA;
               
            }
    Last edited by Inquity; December 5th, 2011 at 04:26 PM. Reason: Forgot some details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured