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:

[IMG]http://img159.imageshack.us/img159/3107/gpacalcgy7.png[/img]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace gpacalc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void textBox8_TextChanged(object sender, EventArgs e)
        {
           
        }


        private void button1_Click(object sender, EventArgs e)
        {
            int x = 0;


            try
            {

                double g1 = Convert.ToDouble(textBox1.Text);
                double g2 = Convert.ToDouble(textBox2.Text);
                double g3 = Convert.ToDouble(textBox3.Text);
                double g4 = Convert.ToDouble(textBox4.Text);
                double g5 = Convert.ToDouble(textBox5.Text);
                double g6 = Convert.ToDouble(textBox6.Text);
                double g7 = Convert.ToDouble(textBox7.Text);
                textBox8.Text = Convert.ToString((g1 + g2 + g3 + g4 + g5 + g6 + g7) / 7.0);
                

                
            }
            catch
            {
                Console.Write(textBox8.Text = "ERROR");
                Console.Beep(x = 266, x = 300);
            }

        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}

If you could help me on this it would be greatly appreciated. :)

1st

dont calculate and display in a text box in one move. first calculate to a variable.

g8 = (g1 + g2 + g3...... + g7) / 7.0;

2nd

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

string s1;

if ( g8 > 3.7 && g8 <= 4.0 )
    s1 = "A";

if ( g8 > 3.3 && g8 <= 3.7 )
    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.

Comments
excellent answer
This article has been dead for over six months. Start a new discussion instead.