First programming class project... help me!

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Levio91
Chaos Rift Regular
Chaos Rift Regular
Posts: 119
Joined: Thu Nov 06, 2008 9:50 pm

First programming class project... help me!

Post by Levio91 »

http://tinyrealm.com/~efa/cisc2305/cisc2305_l4.php

Thats the lesson thing I need to do. I already created the gui (using visual C# 2008) I just dont know how I add this code routine.

Code: Select all

public bool IsNumeric(string s)
{
try
{
Double.Parse(s);
}
catch
{
return(false);
}

return(true);
} 
This is what I have so far
lab5.zip
Lab 5
(44.47 KiB) Downloaded 112 times
It says something about making it a method... someone please explain
"Criticism is something you can avoid easily by saying nothing, doing nothing, and being nothing. " - Aristotle

http://www.facebook.com/profile.php?id= ... ef=profile
Image
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: First programming class project... help me!

Post by LeonBlade »

That public bool IsNumeric is the method.

A method is a function inside a class, you call a method in order to do something.
It's used so that you can do something dynamic, or use it over and over again, saving you lot's of time in writing code and making it more efficient.

Where you have the IsNumeric method is fine right now, it needs to be inside of the class braces and not inside any other methods...

Code: Select all

class 
{

   method 
   {
      // do stuff
   }

   method 
   {
      // do stuff
   }   

}
Now you need to make a button event handler.
The easiest way to do this is just by double clicking on the button in the Design view.
This will auto-generate the Event Handler code for you and take you right to the method created.
You should defiantly see how it works someday so that you can get an understanding at what it is doing.

You can paste in your other code within that new button click method you just created...

Code: Select all

if(IsNumeric(TextBox1.Text) == true)
{
        // your temp convert code goes here
}
        else
{
        // your message window code goes here
} 
This code calls the IsNumeric method and is passing in a string(text).
The method is of type bool (boolean) meaning it returns a true or false depending on what it says in the method.
So you can assume by the name IsNumeric it returns true if what you wrote was a number, and false if it wasn't a number.

Everything within the first loop with "your temp convert code goes here" is what you write when you get true.
And the else is for anything other than true, which can only be false (in this case of a boolean).

The method you wrote in is advanced for just beginners however, you might want to either forget that or move on (if you even can) unless you know what Try...Catch is...
Hope this helps.
There's no place like ~/
User avatar
Levio91
Chaos Rift Regular
Chaos Rift Regular
Posts: 119
Joined: Thu Nov 06, 2008 9:50 pm

Re: First programming class project... help me!

Post by Levio91 »

Thanks LeonBlade.

I have another problem though I cant figure out whats wrong with my equation thats supposed to be used to convert celsius to fahrenheit!!!!!! could you look at it and tell me whats wrong this is the equation.

Code: Select all

((temp_c/(5/9))+32);
you can look at the entire code here.
Lab5-MTH.zip
(66.96 KiB) Downloaded 93 times
"Criticism is something you can avoid easily by saying nothing, doing nothing, and being nothing. " - Aristotle

http://www.facebook.com/profile.php?id= ... ef=profile
Image
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: First programming class project... help me!

Post by dandymcgee »

Levio91 wrote:Thanks LeonBlade.
I have another problem though I cant figure out whats wrong with my equation thats supposed to be used to convert celsius to fahrenheit!!!!!! could you look at it and tell me whats wrong this is the equation.

Code: Select all

((temp_c/(5/9))+32);
Should be:

Code: Select all

((temp_c*(9/5))+32);
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Levio91
Chaos Rift Regular
Chaos Rift Regular
Posts: 119
Joined: Thu Nov 06, 2008 9:50 pm

Re: First programming class project... help me!

Post by Levio91 »

That got it working better. but It still isnt accurate. I need it to convert fahrenheit to celcius.
"Criticism is something you can avoid easily by saying nothing, doing nothing, and being nothing. " - Aristotle

http://www.facebook.com/profile.php?id= ... ef=profile
Image
User avatar
Levio91
Chaos Rift Regular
Chaos Rift Regular
Posts: 119
Joined: Thu Nov 06, 2008 9:50 pm

Re: First programming class project... help me!

Post by Levio91 »

I got it to work.

Code: Select all

((temp_c / (5.0 / 9.0)) + 32);
Now all I need to know is how to make this file an exe like when I install games and stuff...

Id let you download it but maximum download size is 256 kb the program is 276 kb...

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//*********************************************************
// Convert:: A simple conversion example
// Levi Harman A.K.A.  (mth)
// ********************************************************
// Date        Comments                                pgr
// =====       =========                               ====
// 2/10/09     First working version with input tests  mth
//*********************************************************
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {

            float temp_c;
            float temp_f;

            InitializeComponent();
        }

        public bool IsNumeric(string s)
        {
            try
            {
                Double.Parse(s);
            }
            catch
            {
                return (false);
            }

            return (true);
        } 




        // f2c
        private void button1_Click(object sender, EventArgs e)
        {
            float temp_f = 0;
            float temp_c = 0;


            if (IsNumeric(textBox1.Text) == true)
            {
                // temp convert code goes here
                temp_f = float.Parse(textBox1.Text);

                temp_c = (float) ((temp_f - 32) * 5 / 9.0);

                textBox2.Text = temp_c.ToString();
            
            }
            else
            {
                // message window code goes here
                textBox1.Text = "need number";
            } 
        }




        // c2f
        private void button2_Click(object sender, EventArgs e)
        {

            float temp_f = 0;
            float temp_c = 0;


            if (IsNumeric(textBox2.Text) == true)// validity test
            {
                temp_c = float.Parse(textBox2.Text);
                temp_f = (float)((temp_c / (5.0 / 9.0)) + 32);
                textBox1.Text = Convert.ToString(temp_f);
            }
            else
            {
                textBox2.Text = "need a number";
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
"Criticism is something you can avoid easily by saying nothing, doing nothing, and being nothing. " - Aristotle

http://www.facebook.com/profile.php?id= ... ef=profile
Image
User avatar
Levio91
Chaos Rift Regular
Chaos Rift Regular
Posts: 119
Joined: Thu Nov 06, 2008 9:50 pm

Re: First programming class project... help me!

Post by Levio91 »

heres an image of it runningImage
"Criticism is something you can avoid easily by saying nothing, doing nothing, and being nothing. " - Aristotle

http://www.facebook.com/profile.php?id= ... ef=profile
Image
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: First programming class project... help me!

Post by MarauderIIC »

Build a release (under proj->active configuration, then push build) and then pull the exe out of project/release directory. But if you're using MSVS it might not run on the other computer for reasons explained (obfuscated, perhaps) in the links in this news post.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: First programming class project... help me!

Post by LeonBlade »

Also, you might want to rename that "Form1" dialog text to something more appropriate.
And you have some methods that the code made for you that aren't used, you should remove those as well...
Then maybe make your own Icon and then you got an impressive program :) (for a beginner lol)
There's no place like ~/
User avatar
KuramaYoko10
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 55
Joined: Fri Oct 31, 2008 8:02 pm

Re: First programming class project... help me!

Post by KuramaYoko10 »

Levio91 wrote:
Now all I need to know is how to make this file an exe like when I install games and stuff...
You said you are using Microsoft Visual C#? I am using the Microsoft Visual Studio 2008 so it should look alike (I guess), here is how I do it... (I believe it doesnt have this feature in the express edition though):

- You right click "Solution" in the Solution's Panel, and click add -> New Project
- Look for the "Other Project Types -> Setup & Deployment" , and select Setup Project
- Then you can do several things with this, add a shortcut to the users desktop, decide which files you want to insert in the folder, where to install it, do registry keys and etc... you have to play with it, but the basic is to right click "Application Folder" and select "add -> Project Output"
- Then you just have to build the project again, and the Setup folder will be created inside your projects folder... then you have just to install it using either the setup.exe or setup.msi

Tried to do my best explaining it xD... try it and pm me if you have any questions with it ;)
Type a message here!!
[b][color=#BF0000]MarauderIIC[/color][/b] wrote:"Never" is never true in programming.
Post Reply