Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 30th, 2007, 01:02 AM
Registered User
 
Join Date: Nov 2007
Location: , , .
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. :)

Reply With Quote
  #2 (permalink)  
Old November 30th, 2007, 03:25 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.