2 Replies - 1530 Views - Last Post: 09 March 2013 - 12:32 PM Rate Topic: -----

#1 boingbunny   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-March 13

Addition Problems Checker

Posted 09 March 2013 - 12:11 PM

Hello, I am making an addition problems generator. Basically it is just an application that will generate a random addition problem for a user to answer, and input an answer into a separate TextBox. I have created a Button to do that, this is what I have so far and it works. This code generates random numbers from 100 through 500 and the random numbers should show on a that Label, below.

private void Newproblem_Click(object sender, EventArgs e)
            Random Numbers = new Random();
            int number1;
            int number2;
            int Sum;

            number1 = Numbers.Next(400) + 101;
            number2 = Numbers.Next(400) + 101;
            theproblemLabel.Text = number1 + "  +  " + number2.ToString();

My question is, what could I do to let a user know that their answer is correct, or incorrect? I have made a separate Button for it, and when a user clicks it after they have inserted an answer, a MessageBox.Show should pop up indicating whether or not their answer is correct, or if they even submitted any. Sorry if I worded anything oddly, I am completely new at programming. I have tried googling "check addition answer C#" but it's not that relevant to my question at all. Please tell me what methods I should use, and how to do it. I would greatly appreciate the help. Thanks in advanced.

Is This A Good Question/Topic? 0
  • +

Replies To: Addition Problems Checker

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6534
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Addition Problems Checker

Posted 09 March 2013 - 12:29 PM

Don't make a new Random every time you click the button.
Make 1 Random instance for the entire class, then just call .Next to make a new number.


a MessageBox.Show should pop up indicating whether or not their answer is correct,

Personally I hate lots of messgeboxes. They look so 1990's and have issues like showing up on monitor 1 even if the application is on monitor 3. I think it would be a lot cleaner to stick to a one-screen interface. You can show/hide a lable and set its text to "Hurray" or "Booo" for example. That way the lable just appears when they answer the question.

So you're really asking ... "How do I architect and build my entire program?"

Would someone show me how to build my program? - Read this article

If you are *this* new to programming, you shouldn't be developing a game from scratch. You simply don't know how much you don't know.The bad use of Random in your example is just one such thing. You should just be working on learning, not designing.

My standard beginner resources post - Updated JAN 2013

Plan your study route:
There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)

For the life of me I can't figure out why people try 1 & 2. I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

  • First learn the language by working 2-5 "Learn C# in 30 days" type books cover to cover.
  • Do a dozen on-line tutorial projects where you build what you're told to build, the way you are told to build it WITH AN EXPLANATION OF WHY so you can learn.
  • Learn to plan before you type.
  • THEN you start designing software with a purpose.

I don't learn from reading books: I learn by doing.

Newbie/Rookie said:

I have little/no programming experience but I need to write a program by Friday that does XYZ.

Resources, references and suggestions for new programmers.

This post has been edited by tlhIn`toq: 09 March 2013 - 12:30 PM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is online

  • blow up my boots
  • member icon

Reputation: 6549
  • View blog
  • Posts: 26,553
  • Joined: 12-December 12

Re: Addition Problems Checker

Posted 09 March 2013 - 12:32 PM

Store the answer in your Sum variable:

Sum = number1 + number2;

but this Sum needs to be available to another button so it should be declared outside of these buttons as an instance variable.

Then when the user clicks a button to check the answer you can compare:

if (Sum == Int32.Parse(txtAnswer.Text)) {

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1