Create Mathematics Program

Associate
Joined
17 Nov 2011
Posts
852
I'm working on a small project which I want to create a mathematics program to help me out, it's based on mathematics, I was thinking if I can create it using Microsoft Visual Studio

This is how I want it to work,

It must have 10 input boxes for me to input the numbers, each box contains two numbers, input numbers will be from 1 to 37

After I have input the numbers into the 10 input boxes, it will generate a 10x10 grid of numbers by using this mathematics calculation method,

For example, if I have input 12 and 27 into the first input box, it will calculate it as 27-12 = 15, if the answer is positive then always leave it as it is

If the answer is negative for example, if I input 36 and 19, it will calculate it as 19-36 = -17, the answer is negative so it will need to add 37 to the answer which will be -17+37 = 20, so 20 will be the final answer

For example in the screenshot, 21-15 = 6, the answer 6 will be placed in S1 column and 19 - 6 = 13, the answer 13 will be placed in S2 column, it's always the bottom number minus the top number

In the screenshot, I only showed 5 boxes of input numbers and 5 columns so it doesn't confuse you, but once it's finished, it will have 10 input boxes and 10 columns

bgSnp.jpg
 
Associate
Joined
14 May 2010
Posts
1,136
Location
Somerset
It would be quicker and easier to do it in Excel. In fact, I've just put one together for the values you've listed here - https://www.dropbox.com/s/zq6wvrdzmbrk3gh/MathematicsProgram.xls?m

Just set your values in the left hand column and the spreadsheet will automatically recalcuate your required values.

[edit] Just re-read your original post - if this is an exercise for yourself in visual studio then yes, it's completely possible. You would need to create a Form containing 20 text boxes down the left hand side, and then enough labels to handle all the outputs. Much easier to do it in Excel though! :)
 
Last edited:
Soldato
Joined
16 Feb 2004
Posts
4,811
Location
London
you could try downloading a program called linqpad, allows you to test and run small bit's of c# code really easily. Set the language to C# Statements and try this.

Code:
var rnd = new Random();
var workList = new List<List<int>>{new List<int>()};

// fill initial values
for (var i = 0; i < 10; i++)
	workList[0].Add(rnd.Next(1, 37));
// or
//workList[0] = new List<int>{1,2,3,4,5,6,7,8,9,10};

var loopCount = 0;
while(loopCount < workList[0].Count - 1)
{
	workList.Add(new List<int>());
	
	for (var i = 0; i < workList[loopCount].Count - 1; i++)
	{
		var tempNo = workList[loopCount][i+1] - workList[loopCount][i];
		workList[loopCount + 1].Add(tempNo < 0 ? tempNo + 37 : tempNo);
	}
	
	loopCount++;
}

workList.Dump("Final values");
 
Associate
OP
Joined
17 Nov 2011
Posts
852
It would be quicker and easier to do it in Excel. In fact, I've just put one together for the values you've listed here - https://www.dropbox.com/s/zq6wvrdzmbrk3gh/MathematicsProgram.xls?m

Just set your values in the left hand column and the spreadsheet will automatically recalcuate your required values.
Thanks, I'll check the Excel file tomorrow and try it out

[edit] Just re-read your original post - if this is an exercise for yourself in visual studio then yes, it's completely possible. You would need to create a Form containing 20 text boxes down the left hand side, and then enough labels to handle all the outputs. Much easier to do it in Excel though! :)
I'll see how the Excel file goes tomorrow, if it's good then I'll stick with Excel if not then I'll create one in Visual Studio but I don't know the coding of the maths calculation

you could try downloading a program called linqpad, allows you to test and run small bit's of c# code really easily. Set the language to C# Statements and try this.

Code:
var rnd = new Random();
var workList = new List<List<int>>{new List<int>()};

// fill initial values
for (var i = 0; i < 10; i++)
	workList[0].Add(rnd.Next(1, 37));
// or
//workList[0] = new List<int>{1,2,3,4,5,6,7,8,9,10};

var loopCount = 0;
while(loopCount < workList[0].Count - 1)
{
	workList.Add(new List<int>());
	
	for (var i = 0; i < workList[loopCount].Count - 1; i++)
	{
		var tempNo = workList[loopCount][i+1] - workList[loopCount][i];
		workList[loopCount + 1].Add(tempNo < 0 ? tempNo + 37 : tempNo);
	}
	
	loopCount++;
}

workList.Dump("Final values");
I've downloaded Linqpad and tried the code you provided, it came out with boxes under boxes
 
Associate
OP
Joined
17 Nov 2011
Posts
852
@ZombieFan

I've tested the Excel file and it works like the way I wanted to, also just incase, I want to create the same thing in Visual Studio as well but I don't know the coding of the maths calculation
 
Soldato
Joined
16 Feb 2004
Posts
4,811
Location
London
I've downloaded Linqpad and tried the code you provided, it came out with boxes under boxes

Yep that's the idea, it gives you a list of all the steps, each step is a list of the numbers so you can use this to bind to a windows app. It's just the 'maths engine' bit.
 
Back
Top Bottom