|
-
December 5th, 2011, 03:31 PM
#1
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
-
December 5th, 2011, 03:40 PM
#2
Re: C# can't figure out whats going wrong
I apologize in advanced for not using the got a little ahead of myself, and i'm using the .NET 4.0
-
December 5th, 2011, 04:32 PM
#3
Re: C# can't figure out whats going wrong
You didn't mention what the problem is, but
if (grade > 50)
{
GPA = 0.0;
}
so any grade above 50 will yield a GPA of 0.0. I don't think you want that.
Developing using:
.NET3.5 / VS 2010
-
December 5th, 2011, 04:40 PM
#4
Re: C# can't figure out whats going wrong
Not able to see al your code on the phone screen but your not mentioning the issue you are having.
From what I am guessing is your gpa not calculating right and that would be due to your if conditions.
Code:
// This way makes anything lower than 50 a gpa 0
If (grade <= 50)
gpa = 0;
// This way makes anything greater than 50 a gpa 0
If (grade >= 50)
gpa = 0;
Thats pretty much what I can tell without explanation or a bigger screen. If one of the more experienced members hasn't helped you out by the time I get home I'll try to assist better.
-
December 5th, 2011, 04:41 PM
#5
Re: C# can't figure out whats going wrong
I just switched around, but it seems no matter what i do grade always turns up as 0, I'm just trying to get it to calculate the GPA when a user adds a course to a listbox.
-
December 5th, 2011, 04:44 PM
#6
Re: C# can't figure out whats going wrong
Oh Jesus it started work thank you for the responses guys I gotta drill those greater than and less than in my head so I don't continually get them mixed up.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|