CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Math project!

  1. #1
    Join Date
    Nov 2009
    Posts
    61

    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

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    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.

  3. #3
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    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;
               }

  4. #4
    Join Date
    Nov 2009
    Posts
    61

    Re: Math project!

    I made the "math" codes. I just need the number generator now

  5. #5
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Math project!

    what kind of number generator?? Clarify your question....

  6. #6
    Join Date
    Nov 2009
    Posts
    61

    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

  7. #7
    Join Date
    Sep 2006
    Posts
    31

    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

  8. #8
    Join Date
    Nov 2009
    Posts
    61

    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 !

  9. #9
    Join Date
    Sep 2006
    Posts
    31

    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.

  10. #10
    Join Date
    Nov 2009
    Posts
    61

    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.

  11. #11
    Join Date
    Nov 2009
    Posts
    61

    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!

  12. #12
    Join Date
    Nov 2009
    Posts
    61

    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.

  13. #13
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Math project!

    Quote Originally Posted by Mikepoulsen View Post
    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

  14. #14
    Join Date
    Nov 2009
    Posts
    61

    Re: Math project!

    Memeloo i love u <3!

  15. #15
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Math project!

    Quote Originally Posted by Mikepoulsen View Post
    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured