Click to See Complete Forum and Search --> : Help a noob out


Mestedup
August 21st, 2008, 04:40 PM
ok, to give you a little background on what I'm doing.... I decided that I wanted to learn how to program in C# (in my free time) and I've learned a few things here and there. (currently reading C# for dummies) now I wanted to try to make a app of my own. when I try to run it I get a error. but with me being new, I really dont know how to fix it. I was wondering if some one here would be able to help me.


Here is the code I'm working on:

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

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{

}

private void label6_Click(object sender, EventArgs e)
{

}

private void find_Click(object sender, EventArgs e)
{

}

private void find2_Click(object sender, EventArgs e)
{
int soulution2;
int numerator;
int denominator;
int result = numerator / denominator;
return solution2=result;
}
}
}

darwen
August 21st, 2008, 04:52 PM
Welcome to the forum.

Firstly in future can you please use code tags (see the link in my signature) - it makes code much more readable.

Secondly you should post the error you're getting in future : most of the time it's very difficult to spot what's wrong with code just by inspection.

However in this case I'd hazard a guess that you're getting a divide by zero error at these lines :


int numerator;
int denominator;
int result = numerator / denominator;


You haven't set numerator or denomintor to anything so both will be zero leading to


result = 0 / 0;


hence the divide by zero error.

The compiler is probably also warning you that you've used variables without setting them which is true since you haven't set numerator, denominator or solution2 to be anything.

Also you only use a 'return' when a function returns a value : in the case of find2_Click the return type is 'void' meaning it doesn't return anything.

Darwen.

boudino
August 22nd, 2008, 02:03 AM
I guess it is compile-time error, your code looks strange. The last line in find2_Click - you cannot return a value from method with void as return type in its signature.

Mestedup
August 22nd, 2008, 08:44 PM
Well what I'm trying to do is have it so that the user will input a fraction and the program will return a decimal. Like I said I'm new to all of this so I'm trying to learn a lot all at once. I"m going to guess that the "find2_Click" is the button I made. I want the button to "find" the decimal of the fraction. I am getting the "variable not set". The Solution2 is where I want the decimal to be written to.

Arjay
August 24th, 2008, 04:16 PM
You might be better off starting with a console application and learn some of the basics of C#. You can prompt the user to enter the numerator and again for the denominator. From there you can output the result (or whatever you wish to display).

After you get this down, you can then learn about how to code a UI form, connect buttons and so forth.

Once you learn a bit of the basics in a console app, it will be easier to move to the UI later.

If you try to do it all at once, well then, it's not so easy.