GPA Calculator

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 1
Reputation: xenoalien is an unknown quantity at this point 
Solved Threads: 0
xenoalien xenoalien is offline Offline
Newbie Poster

GPA Calculator

 
0
  #1
Nov 30th, 2007
I need some help. I want to be able to put in a letter grade within a textbox of a class and have the program know that A is 4.0 (A=4.0) then calclulate the GPA by adding all the class grades and dividing by seven which is the number of classes which equals the GPA.

This is what it looks like:

A = 4.0
A- =3.7
B+ = 3.3
B = 3.0
B- =2.7
C+=2.3
C=2.0
C-=1.7
NG = 0



My code looks like this so far it just doesn't know how to interpret A as 4.0 and calculate the GPA:

http://img159.imageshack.us/img159/3107/gpacalcgy7.png
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace gpacalc
  10. {
  11. public partial class Form1 : Form
  12. {
  13. public Form1()
  14. {
  15. InitializeComponent();
  16. }
  17.  
  18. private void label1_Click(object sender, EventArgs e)
  19. {
  20.  
  21. }
  22.  
  23. private void label4_Click(object sender, EventArgs e)
  24. {
  25.  
  26. }
  27.  
  28. private void textBox8_TextChanged(object sender, EventArgs e)
  29. {
  30.  
  31. }
  32.  
  33.  
  34. private void button1_Click(object sender, EventArgs e)
  35. {
  36. int x = 0;
  37.  
  38.  
  39. try
  40. {
  41.  
  42. double g1 = Convert.ToDouble(textBox1.Text);
  43. double g2 = Convert.ToDouble(textBox2.Text);
  44. double g3 = Convert.ToDouble(textBox3.Text);
  45. double g4 = Convert.ToDouble(textBox4.Text);
  46. double g5 = Convert.ToDouble(textBox5.Text);
  47. double g6 = Convert.ToDouble(textBox6.Text);
  48. double g7 = Convert.ToDouble(textBox7.Text);
  49. textBox8.Text = Convert.ToString((g1 + g2 + g3 + g4 + g5 + g6 + g7) / 7.0);
  50.  
  51.  
  52.  
  53. }
  54. catch
  55. {
  56. Console.Write(textBox8.Text = "ERROR");
  57. Console.Beep(x = 266, x = 300);
  58. }
  59.  
  60. }
  61. private void textBox1_TextChanged(object sender, EventArgs e)
  62. {
  63.  
  64. }
  65.  
  66. private void button2_Click(object sender, EventArgs e)
  67. {
  68. Close();
  69. }
  70. }
  71. }


If you could help me on this it would be greatly appreciated.
Last edited by cscgal; Nov 30th, 2007 at 1:03 am. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 164
Reputation: Ravenous Wolf is an unknown quantity at this point 
Solved Threads: 1
Ravenous Wolf Ravenous Wolf is offline Offline
Junior Poster

Re: GPA Calculator

 
1
  #2
Nov 30th, 2007
1st

dont calculate and display in a text box in one move. first calculate to a variable.
  1. g8 = (g1 + g2 + g3...... + g7) / 7.0;

2nd

now you can use g8 in a series of selection structures structure

  1.  
  2. string s1;
  3.  
  4. if ( g8 > 3.7 && g8 <= 4.0 )
  5. s1 = "A";
  6.  
  7. if ( g8 > 3.3 && g8 <= 3.7 )
  8. s1 = "B";
and so on until each grade is checked for. now you display the value of g8 in a textbox and the of s1, which is the grade, as well.
Last edited by Ravenous Wolf; Nov 30th, 2007 at 3:07 am.
... what society overwhelmingly asks for is snake oil. Of course, the snake oil has the most impressive names —otherwise you would be selling nothing— like "Structured Analysis and Design", "Software Engineering", "Maturity Models", "IPSE", "MIS", "OO", "BPRE".... by Edsger W. Dijkstra
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC