How to display "A" Grade

Did the math, but dont know where to go next

Page 1 of 1

13 Replies - 3193 Views - Last Post: 28 September 2009 - 12:30 PM Rate Topic: -----

#1 uncles   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 30-November 08

How to display "A" Grade

Posted 25 September 2009 - 07:53 AM

Objective: Code a one-form project to calculate one student's grade for a semester (already did that),
Enter the student's Name, ID, exc exc (did that part too)
Choose options to show grade as well as the number grade using 8 or 10 point system
(this part I dont get)


This code is under the Calculate Butten:

  private void calculateButton_Click(object sender, EventArgs e)
		{
			//---Local Variables---//
			decimal grade = 0M, homeWork, midTerm, final, quizzes, projects, participation, pointscale = 0M;

			try
			{
				homeWork = Decimal.Parse(hwTextBox.Text);
				midTerm = Decimal.Parse(midtermTextBox.Text);
				final = Decimal.Parse(finalTextBox.Text);
				quizzes = Decimal.Parse(quizzTextBox.Text);
				projects = Decimal.Parse(projectsTextBox.Text);
				participation = Decimal.Parse(partTextBox.Text);
				if (homeWork < 0 || homeWork > 100)
					MessageBox.Show("Homework must be between 0-100");
				if (midTerm < 0 || midTerm > 100)
					MessageBox.Show("Homework must be between 0-100");
				if (final < 0 || final > 100)
					MessageBox.Show("Homework must be between 0-100");
				if (quizzes < 0 || quizzes > 100)
					MessageBox.Show("Homework must be between 0-100");
				if (projects < 0 || projects > 100)
					MessageBox.Show("Homework must be between 0-100");
				if (participation < 0 || participation > 100)
					MessageBox.Show("Homework must be between 0-100");

				grade = (homeWork * .10M) + (midTerm * .15M) + (final * .20M) + (quizzes * .20M) + (projects * .30M) + (participation * .05M);
				finalTB.Text = grade.ToString(); // convert decimal from grade ==> string value in box

				//int minA, minB, minC, minD, minF
				// int scale = 8pointcheck, 10point
				//
				// minA = 100-scale
				// minB = 100-(scale * 2)
				// minC = 100-(scale * 3)
			  

			}

			catch (Exception ex)
			{
				MessageBox.Show("Please enter 0 - 100 for each grade");

			}

		   

			
			
		} 
		


How do I display the letter grade between a 8 point or 10 point system?

Is This A Good Question/Topic? 0
  • +

Replies To: How to display "A" Grade

#2 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: How to display "A" Grade

Posted 25 September 2009 - 08:02 AM

assuming the rest of your code is correct..

// in a 10 point system
string gradeLetter = string.Empty;

if (grade >= 90 && grade <= 100)
     gradeLetter = "A";  
else if (grade >= 80 && grade < 90)
     gradeLetter = "B";
else if (grade >= 70 && grade < 80)
     gradeLetter = "C";
else if (grade >= 60 && grade < 70)
     gradeLetter = "D";
else if (grade < 60)
     gradeLetter = "F";


Was This Post Helpful? 0
  • +
  • -

#3 uncles   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 30-November 08

Re: How to display "A" Grade

Posted 25 September 2009 - 09:23 AM

View Posteclipsed4utoo, on 25 Sep, 2009 - 07:02 AM, said:

assuming the rest of your code is correct..

// in a 10 point system
string gradeLetter = string.Empty;

if (grade >= 90 && grade <= 100)
     gradeLetter = "A";  
else if (grade >= 80 && grade < 90)
     gradeLetter = "B";
else if (grade >= 70 && grade < 80)
     gradeLetter = "C";
else if (grade >= 60 && grade < 70)
     gradeLetter = "D";
else if (grade < 60)
     gradeLetter = "F";



Thats great! but now how will the program know to switch from 8 point to 10 point system if the user clicks between the two?
(I set 8 point system as the default setting if that helps)
Was This Post Helpful? 0
  • +
  • -

#4 Codey09   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 214
  • Joined: 20-August 09

Re: How to display "A" Grade

Posted 25 September 2009 - 09:48 AM

You could use a switch statement to do that

			int pointSystem = 8;
			switch (pointSystem)
			{
				case 8:
					// Enter Code Here
					break;
				case 10:
					// Enter Code Here
					break;
			}

Was This Post Helpful? 1
  • +
  • -

#5 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7482
  • View blog
  • Posts: 15,507
  • Joined: 16-October 07

Re: How to display "A" Grade

Posted 25 September 2009 - 10:34 AM

View Postuncles, on 25 Sep, 2009 - 10:23 AM, said:

Thats great! but now how will the program know to switch from 8 point to 10 point system if the user clicks between the two?
(I set 8 point system as the default setting if that helps)


Start using some methods. Really.

private char getGradeLetter10(double grade) {
	if (grade>100) { return '*' }
	if (grade>=90) { return 'A' }
	if (grade>=80) { return 'B' }
	if (grade>=70) { return 'C' }
	if (grade>=60) { return 'D' }
	return 'F';
}

private char getGradeLetter8(double grade) { /* your code here */ }

private decimal parseAndValidate(string s) {
	decimal d = Decimal.Parse(s);
	if (d < 0 || d > 100) { throw new Exception("Homework must be between 0-100"); }
	return d;
}


This post has been edited by baavgai: 25 September 2009 - 10:35 AM

Was This Post Helpful? 0
  • +
  • -

#6 uncles   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 30-November 08

Re: How to display "A" Grade

Posted 25 September 2009 - 04:11 PM

Thank you all for your input! but I am still struggling through this
Now that the math is out of the way, I am simply thinking that now it will display the grade in the textbox..
got 10 errors like this:

Error: Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox' 101 43

What am I overlooking?

Using codey's method:

				int pointSystem = 8;
				switch (pointSystem)
				{
					case 8:
						// 8 point System
						if (grade >= 84 && grade < 92) //letterGrade being textboxform
>							letterGrade = "A";
						else if (grade >= 84 && grade < 92)
>							letterGrade = "B";
						else if (grade >= 76 && grade < 84)
>...							letterGrade = "C";
						else if (grade >= 68 && grade < 76)
							letterGrade = "D";
						else if (grade < 60)
							letterGrade = "F";
						break;

					case 10:
						// 10 point System
						if (grade >= 80 && grade < 90)
							letterGrade = "A";
						else if (grade >= 80 && grade < 90)
							letterGrade = "B";
						else if (grade >= 70 && grade < 80)
							letterGrade = "C";
						else if (grade >= 60 && grade < 70)
							letterGrade = "D";
						else if (grade < 60)
							letterGrade = "F";

						break;
				}
			  

			}

			catch (Exception ex)
			{
				MessageBox.Show("Please enter 0 - 100 for each grade");

			}


This post has been edited by uncles: 25 September 2009 - 04:12 PM

Was This Post Helpful? 0
  • +
  • -

#7 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7482
  • View blog
  • Posts: 15,507
  • Joined: 16-October 07

Re: How to display "A" Grade

Posted 25 September 2009 - 04:34 PM

Is letterGrade a TextBox? Perhaps you want to say something like letterGrade.Text="A";?
Was This Post Helpful? 1
  • +
  • -

#8 uncles   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 30-November 08

Re: How to display "A" Grade

Posted 25 September 2009 - 05:39 PM

View Postbaavgai, on 25 Sep, 2009 - 03:34 PM, said:

Is letterGrade a TextBox? Perhaps you want to say something like letterGrade.Text="A";?


Yes letterGrade is a TextBox and the letterGrade.Text="A"; did work!
I compiled and 0 bugs, the Only problem left is to figure out why 8 and 10 point systems are not getting along. I made 8 point system default, so that when the user clicks the check box, the groupBox pops up with the 2 systems showing along with TextBox showing the grade. When I click "Calculate" It does only the 8 point even if you quickly switch between the two.

almost at the finish line! any help would be great! Thanks!

This post has been edited by uncles: 25 September 2009 - 05:40 PM

Was This Post Helpful? 0
  • +
  • -

#9 Codey09   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 214
  • Joined: 20-August 09

Re: How to display "A" Grade

Posted 26 September 2009 - 06:13 AM

When the user clicks the checkbox for the 10 point system make sure the variable pointSytem is set to 10, then when it gets to the switch statement it should use the 10 point system.

Also make sure the you declare the pointSystem variable at the begining of the code and not where I put it in my example as if you dont it will always reset it to 8 and will only use the 8 point system(hope that made senses lol).
Was This Post Helpful? 1
  • +
  • -

#10 uncles   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 30-November 08

Re: How to display "A" Grade

Posted 26 September 2009 - 06:03 PM

View PostCodey09, on 26 Sep, 2009 - 05:13 AM, said:

When the user clicks the checkbox for the 10 point system make sure the variable pointSytem is set to 10, then when it gets to the switch statement it should use the 10 point system.

Also make sure the you declare the pointSystem variable at the begining of the code and not where I put it in my example as if you dont it will always reset it to 8 and will only use the 8 point system(hope that made senses lol).


Im a little confused, I changed the int pointSystem =8; to --> int pointSystem =10; and move it before my caculations math? Either way, It still doesnt seem to want to switch between the two.


uptodate code:

 private void calculateButton_Click(object sender, EventArgs e)
		{
			//---Local Variables---//
			decimal grade = 0M, homeWork, midTerm, final, quizzes, projects, participation, pointscale = 0M;
			int pointSystem = 0;
			
			
			try
			{
				homeWork = Decimal.Parse(hwTextBox.Text);
				midTerm = Decimal.Parse(midtermTextBox.Text);
				final = Decimal.Parse(finalTextBox.Text);
				quizzes = Decimal.Parse(quizzTextBox.Text);
				projects = Decimal.Parse(projectsTextBox.Text);
				participation = Decimal.Parse(partTextBox.Text);
				if (homeWork < 0 || homeWork > 100)
					MessageBox.Show("Homework must be between 0-100");
				if (midTerm < 0 || midTerm > 100)
					MessageBox.Show("Homework must be between 0-100");
				if (final < 0 || final > 100)
					MessageBox.Show("Homework must be between 0-100");
				if (quizzes < 0 || quizzes > 100)
					MessageBox.Show("Homework must be between 0-100");
				if (projects < 0 || projects > 100)
					MessageBox.Show("Homework must be between 0-100");
				if (participation < 0 || participation > 100)
					MessageBox.Show("Homework must be between 0-100");

				grade = (homeWork * .10M) + (midTerm * .15M) + (final * .20M) + (quizzes * .20M) + (projects * .30M) + (participation * .05M);
				finalTB.Text = grade.ToString(); // convert decimal from grade ==> string value in box

				
				switch (pointSystem) 
				{
					case 8:
						// 8 point System
						if (grade >= 84 && grade < 92) //letterGrade being textboxform
							letterGrade.Text = "A";
						else if (grade >= 84 && grade < 92)
							letterGrade.Text = "B";
						else if (grade >= 76 && grade < 84)
							letterGrade.Text = "C";
						else if (grade >= 68 && grade < 76)
							letterGrade.Text = "D";
						else if (grade < 60)
							letterGrade.Text = "F";
						

						break;

					case 10:
						// 10 point System
						if (grade >= 80 && grade < 90)
							letterGrade.Text = "A";
						else if (grade >= 80 && grade < 90)
							letterGrade.Text = "B";
						else if (grade >= 70 && grade < 80)
							letterGrade.Text = "C";
						else if (grade >= 60 && grade < 70)
							letterGrade.Text = "D";
						else if (grade < 60)
							letterGrade.Text = "F";

						break;
				}
			  

			}

			catch (Exception ex)
			{
				MessageBox.Show("Please enter 0 - 100 for each grade");

			}

		   

			
			
		}

		private void eightPS_CheckedChanged(object sender, EventArgs e)
		{

		}

		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			this.pointScaleGp.Visible = this.pointScaleCB.Checked;
		}

		private void Form1_Load(object sender, EventArgs e)
		{

		}

		private void tenPS_CheckedChanged(object sender, EventArgs e)
		{

		}
	}
}


This post has been edited by uncles: 26 September 2009 - 09:27 PM

Was This Post Helpful? 0
  • +
  • -

#11 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: How to display "A" Grade

Posted 27 September 2009 - 12:25 PM

look at your code. You set "pointSystem" to 0 at the start, yet you never assign it another value. So your switch statement is exiting because "pointSystem" is neither 8 nor 10. You have got to set it to 8 or 10.
Was This Post Helpful? 0
  • +
  • -

#12 Codey09   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 214
  • Joined: 20-August 09

Re: How to display "A" Grade

Posted 27 September 2009 - 02:46 PM

Try adding this if statement
			if (checkBox1.Checked == true && checkBox2.Checked == false)
			{
				pointsystem = 8;
			}
			else if (checkBox1.Checked == false && checkBox2.Checked == true)
			{
				pointsystem = 10;
			}
			else if (checkBox1.Checked = true && checkBox2.Checked == true || checkBox1.Checked == false && checkBox2.Checked == false)
			{
				MessageBox.Show("Please only select one option");
			}

this should solve the problem

This post has been edited by Codey09: 27 September 2009 - 02:58 PM

Was This Post Helpful? 0
  • +
  • -

#13 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: How to display "A" Grade

Posted 28 September 2009 - 05:17 AM

View PostCodey09, on 27 Sep, 2009 - 05:46 PM, said:

Try adding this if statement
			if (checkBox1.Checked == true && checkBox2.Checked == false)
			{
				pointsystem = 8;
			}
			else if (checkBox1.Checked == false && checkBox2.Checked == true)
			{
				pointsystem = 10;
			}
			else if (checkBox1.Checked = true && checkBox2.Checked == true || checkBox1.Checked == false && checkBox2.Checked == false)
			{
				MessageBox.Show("Please only select one option");
			}

this should solve the problem


radiobuttons would be a better choice.
Was This Post Helpful? 0
  • +
  • -

#14 Codey09   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 214
  • Joined: 20-August 09

Re: How to display "A" Grade

Posted 28 September 2009 - 12:30 PM

View Posteclipsed4utoo, on 28 Sep, 2009 - 11:17 AM, said:

View PostCodey09, on 27 Sep, 2009 - 05:46 PM, said:

Try adding this if statement
			if (checkBox1.Checked == true && checkBox2.Checked == false)
			{
				pointsystem = 8;
			}
			else if (checkBox1.Checked == false && checkBox2.Checked == true)
			{
				pointsystem = 10;
			}
			else if (checkBox1.Checked = true && checkBox2.Checked == true || checkBox1.Checked == false && checkBox2.Checked == false)
			{
				MessageBox.Show("Please only select one option");
			}

this should solve the problem


radiobuttons would be a better choice.

yep you would be right there, didn't think of radio buttons.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1