Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2007, 01:02 AM
Registered User
 
Join Date: Nov 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default GPA Calculator


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 calculate 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:

http://img159.imageshack.us/img159/3107/gpacalcgy7.png

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:



 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. :)

 
Old November 30th, 2007, 03:25 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You just need to write a method which takes a string and returns a double and inside has a big switch statement..

e.g.

public double ConvertGpa(string grade)
{
  switch(grade)
  {
    case "A":
      return 7.0;
    case "B":
      return 6.0;
    etc...

   default:
     throw Exception("Unknown grade");
  }
}

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
calculator mojtaba rashidi Visual Studio 2005 0 March 17th, 2008 07:29 AM
Calculator DweeLer Other Programming Languages 1 November 18th, 2005 08:13 AM
calculator kale_tushar C++ Programming 1 January 28th, 2004 01:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.