-
January 15th, 2010, 04:16 PM
#1
Math project!
Hello Coders!
I need a kick starter to genrate randoms +, -,* and / math pieces.
Im going to make a website for School kids showing how to do these math things.
I really only need the generator to be finish. So if a kind soul would be nice to teach me this.
I would be very pleased.
Thank you !
Regards Mike Poulsen
-
January 15th, 2010, 08:12 PM
#2
Re: Math project!
Well, you are not very clear about what you are actually trying to accomplish, but the most simple way of doing this would be to generate a random number and then switch on that number to perform a different operation.
-
January 15th, 2010, 09:54 PM
#3
Re: Math project!
I Got you Problem as a mater of fact I am working on exactly same project......Hope this Helps. Hope you can add '/' feature by yourself..
Code:
string[] ope =
{
"X","+","-"
};
Random aRan = new Random();
int aa = aRan.Next(0, 3);
int a = aRan.Next(1, 100);
int b = aRan.Next(1, 100);
string c = ope[aa];
switch (c)
{
case "X":
realAns = a * b;
break;
case "+":
realAns = a + b;
break;
default:
realAns = a - b;
break;
}
-
January 16th, 2010, 03:32 AM
#4
Re: Math project!
I made the "math" codes. I just need the number generator now
-
January 16th, 2010, 07:52 AM
#5
Re: Math project!
what kind of number generator?? Clarify your question....
-
January 16th, 2010, 02:01 PM
#6
Re: Math project!
Okay i got the "generator" I Stoled the Random Numbers from Rocky, so everything is going good. Know, How can i make my label to Increase with 1 number, each time a person says the right awnser for the math question?
Here is my little code
Code:
if ((textBox1.Text == c.ToString()))
{
int o = 0;
o++;
label4.Text = "1";
}
how do i modify that right xD?
Thanks
-
January 16th, 2010, 02:38 PM
#7
Re: Math project!
On top of your class declare a variable that will hold the score
like
private int score=0;
then you simply do this:
if ((textBox1.Text == c.ToString()))
{
score++;
label4.Text = score;
}
I don't know what you are doing with the int o=0 o++; (because thats pretty useless)
greetz kristof
-
January 16th, 2010, 02:43 PM
#8
Re: Math project!
Hey kris! Thanks for ur awnser. Have i done anything wrong. Or should it not keep ticking each time i press the button?
Here is my intire code
Code:
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;
namespace Skole_projekt_
{
public partial class FormPlus : Form
{
public FormPlus()
{
InitializeComponent();
}
float a, b, c;
private void FormPlus_Load(object sender, EventArgs e)
{
Random Nran = new Random();
int H2 = Nran.Next(1, 100);
int H1 = Nran.Next(1, 100);
int o = 0;
label1.Text = H1.ToString();
label2.Text = H2.ToString();
label3.Text = o.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
a = Convert.ToInt32(label1.Text);
b = Convert.ToInt32(label2.Text);
c = a + b;
label3.Text = c.ToString();
Random Nran = new Random();
int H = Nran.Next(1, 100);
if ((textBox1.Text == c.ToString()))
{
int score = 0;
score++;
label4.Text = score.ToString(); ;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
Also. After this "problem" is solved. I would like to know how to "refresh" the Rnum on button click. Thank you !
-
January 16th, 2010, 02:55 PM
#9
Re: Math project!
You have to declare score outside a methode. Because if you declare it within a methode, the variable will be destroid when you leave the methode and be created each time you enter the methode.. thats why in the code you have now, the only values for score you'll get is 0 or 1.
use
(also for the refreshing can you explain what you want to do a bit more? )
greetz
kristof
Code:
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;
namespace Skole_projekt_
{
public partial class FormPlus : Form
{
private int score = 0;
public FormPlus()
{
InitializeComponent();
}
float a, b, c;
private void FormPlus_Load(object sender, EventArgs e)
{
Random Nran = new Random();
int H2 = Nran.Next(1, 100);
int H1 = Nran.Next(1, 100);
int o = 0;
label1.Text = H1.ToString();
label2.Text = H2.ToString();
label3.Text = o.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
a = Convert.ToInt32(label1.Text);
b = Convert.ToInt32(label2.Text);
c = a + b;
label3.Text = c.ToString();
Random Nran = new Random();
int H = Nran.Next(1, 100);
if ((textBox1.Text == c.ToString()))
{
score++;
label4.Text = score.ToString(); ;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
Last edited by kristof1104; January 16th, 2010 at 03:02 PM.
-
January 16th, 2010, 03:44 PM
#10
Re: Math project!
Thanks KRis! Works now.
By refreshing i mean "update" the random number. Because i want a new math piece to pop if the awnser is correct.
-
January 16th, 2010, 04:24 PM
#11
Re: Math project!
SOLVED!
if ((textBox1.Text == c.ToString()))
{
int H2 = Nran.Next(1, 100);
int H1 = Nran.Next(1, 100);
int o = 0;
label1.Text = H1.ToString();
label2.Text = H2.ToString();
label3.Text = o.ToString();
score++;
label4.Text = score.ToString(); ;
textBox1.Text = "";
}
Im so good! . Thanks kris for helping!
-
January 16th, 2010, 05:05 PM
#12
Re: Math project!
NEW QUESTION!
In my : If ((textBox.Text==c.tostring(())
And my code....
How do i make Else if. Like if the awnser is not corrrect
{
Code, blah blah
}thanks.
A friend told me to try Switch statement. But it's so diffrent from If, in my oppinion.
Could some1 be nice to convert my if statements to switch, so i can learn by seeing?
Because the i can do a default case. To do the if else. I was talking about.
Thanks! Please help me. I appriciate it very much!
Last edited by Mikepoulsen; January 16th, 2010 at 07:04 PM.
-
January 17th, 2010, 05:01 AM
#13
Re: Math project!
Originally Posted by Mikepoulsen
How do i make Else if. Like if the awnser is not corrrect
{
Code, blah blah
}thanks.
you should learn some basics first buy some book or visit msdn http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
January 17th, 2010, 05:17 AM
#14
-
January 17th, 2010, 06:01 PM
#15
Re: Math project!
Originally Posted by Mikepoulsen
Memeloo i love u <3!
Mike, Memeloo's advice is right on. C'mon, the folks answering questions here are volunteers. As such, it's expected that folks asking questions need to have a basis in the language they are trying to program in. So getting a basic C# book and working through the chapters is the best way to start. Keep in mind that as you do this, you can post any questions you may have while working through the book. We'll be happy to answer these basic questions.
However, it's a bit misuse of the forum, if you are asking more advance questions (like details of programming a game) and then pop out with a basic question like "how do I program a while loop".
A question like that in the middle of an advanced question is going to frustrate folks doing the answering because a basic level of understanding is expected before someone tackles an advanced subject. It's frustrating because it takes too much time to explain an advanced concept only to find out that the OP doesn't understand the basic syntax of the language.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|