I decided to learn programming today, and so far have made a program to keep my mental arithmetic going (as it’s a bit rubbish).
Most of it I did in the window designer, but here si the source if anyone wants it:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{ private const int max = 10000;
private Random random = new Random();
private int correct;
public Form1()
{
InitializeComponent();
all();
}
private void all(){
int a;
int b;
switch (r(4)){
case 1: //multiply
this.Op.Text = "×";
this.Op1.Text = Convert.ToString(a = r(max));
this.Op2.Text = Convert.ToString(b = r(max / a));
correct = a * b;
break;
case 2: //divide
this.Op.Text = "÷";
this.Op2.Text = Convert.ToString(b = r(max));
correct = r(max / b);
this.Op1.Text = Convert.ToString(correct * b);
break;
case 3: //add
this.Op.Text = "+";
this.Op1.Text = Convert.ToString(a = r(max));
this.Op2.Text = Convert.ToString(b = r(max - a));
correct = a + b;
break;
case 4: //subtract
this.Op.Text = "-";
correct = r(max);
this.Op2.Text = Convert.ToString(b = r(max - correct));
this.Op1.Text = Convert.ToString(b + correct);
break;
}
}
private int r(int n)
{
return (random.Next(n)) + 1;
}
private void check(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
if (correct == Convert.ToInt32(textBox1.Text))
{
MessageBox.Show("Good");
all();
}
else
{
MessageBox.Show("Bad. Should be " + Convert.ToString(correct));
}
}
}
}
}
This seems suspiciously easy so far…