I wrote a computer program

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()

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

        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("Bad. Should be " + Convert.ToString(correct));

This seems suspiciously easy so far…

ok what does it do?

10 PRINT “Hello World”
20 GOTO 10

That’s about where I quit learning programming.

I prefer

10 PRINT "Hello World ";
20 GOTO 10

It’s a little more aesthetically pleasing.

Reminds me of the old days when I taught computers to kids at summer school in Switzerland…on Apple II computers with green monitors. We had the kids copy page after page of Basic to the computer and then watch in awe as a dot went from one corner of the screen to the other corner. Took forever to do and godforbid you made one teeny error.
But this was “cutting edge” back then and you could find magazines with all sorts of Basic programs like that.

fact:: Int->Int

fact 0 = 1
fact n = n * fact(n-1)

For CS majors, the first thing to do with any new language is to calculate Factorials. If I has a nickle for every damn time …

it looks to me like it checks if the typed in answer to a given arithmetic problem (addition, subtraction, mutiplication or division) with randomly generated values and and a randomly generated operand is correct.

My first program, in LGP-21 machine language, was deciding whether an input expression was a wff (well formed function) from the game WFF n Proof, which I had in high school. Yes, I was a geek. My best in high school was a tic-tac-toe game which I fit into the whole 4K words of memory by changing adds to subtracts for a second pass, and back to adds for the first. Ah, the joys of structured programming.

When I was TAing I got forced to write a recursive PDP-11 assembly language program to do this in front of my class in real time. It worked.

Reminds me of a joke that includes the following