I'm making a math problem generator in visual c#, using a series of random number generators to create a unique math problem each time with some protocols implemented(later to use this for harder difficulties). There are different types of math to be used but right now I'm working on a tutorial to teach simple order of operations. The program right now needs to be able to give a problem to the user and compare their answer, but I only have set up the amount of problem numbers, their values, and symbol generation, with a simple display. I'm looking for any tips or advice on how to go about seperating the arrays that contain the mathValues and symbolCompute/symbolDisplay into a readable math problem (string) and a problem the computer can solve itself (which is a combination of math characters and integers at the moment).
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 AcceleratedAptitude
{
public partial class FormTutorials : Form
{
public FormTutorials()
{
InitializeComponent();
}
//difficulty settings
Random rand = new Random();
int easyValueMin = 1, easyValueMax = 20;
int easyNumMin = 3, easyNumMax = 5;
private void buttonOoO_Click(object sender, EventArgs e)
{
//panel control
panelTutorStart.Visible = false;
//panelTutorStart.BringToFront = false;
panelTutorStart.Enabled = false;
panelOoP.Visible = true;
//panelOoP.BringToFront = true;
panelOoP.Enabled = true;
//number generation
int mathNum = rand.Next(easyNumMin, easyNumMax);
int threshCtr = 0;
int threshold = easyValueMax / 2;
int[] mathValue = new int[mathNum];
for (int ctr = 0; ctr < mathNum; ctr++)
{
//check and change threshold so not all the numbers are too high
mathValue[ctr] = rand.Next(easyValueMin, easyValueMax);
if (mathValue[ctr] > threshold)
threshCtr++;
if (threshCtr > mathNum / 2)
mathValue[ctr] = rand.Next(easyValueMin, threshold);
}
//symbol generation creates 1 symbol less than their are numbers
int symbolNum = mathNum - 1;
int[] symbolValue = new int[symbolNum];
for (int ctr = 0; ctr < symbolNum; ctr++)
{
symbolValue[ctr] = rand.Next(1, 4);
}
char[] symbolCompute = new char[symbolNum];
char[] symbolDisplay = new char[symbolNum];
//converts random numbers in corresponding symbols for display and compute
for (int ctr = 0; ctr < symbolNum; ctr++)
{
switch (symbolValue[ctr])
{
case 1: symbolCompute[ctr] = '+';
symbolDisplay[ctr] = '+';
break;
case 2: symbolCompute[ctr] = '-';
symbolDisplay[ctr] = '-';
break;
case 3: symbolCompute[ctr] = '*';
symbolDisplay[ctr] = 'x';
break;
case 4: symbolCompute[ctr] = '/';
symbolDisplay[ctr] = '÷';
break;
}
}
//problem compute assembly
int problemLength = symbolCompute.Length + mathValue.Length;
char[] problemValue = new char[problemLength];
//fix out of bounds error here
/*
int assemblerCtr = 0;
while (assemblerCtr < problemLength)
{
problemValue[assemblerCtr] = (char)mathValue[assemblerCtr];
assemblerCtr += 2;
}
assemblerCtr = 1;
while (assemblerCtr < problemLength)
{
problemValue[assemblerCtr] = (char)symbolValue[assemblerCtr];
assemblerCtr += 2;
}
String problemCompute = new string(problemValue);
*/
//problem display assembly
var ints = mathValue;
var result = string.Join(",", ints.Select(x => x.ToString()).ToArray());
string result2 = new string(symbolDisplay);
StringBuilder strBuild = new StringBuilder();
strBuild.Append(result);
strBuild.Append(result2);
richTextBoxProblemDisplay.Text = strBuild.ToString();
}
private void buttonBack_Click(object sender, EventArgs e)
{
//panel control
panelTutorStart.Visible = true;
panelTutorStart.Enabled = true;
panelOoP.Visible = false;
panelOoP.Enabled = false;
}
private void buttonNext_Click(object sender, EventArgs e)
{
}
}
}
I'm thinking for the display there a way i can use string.join and use my symbolDisplay with spaces as a delimeter, not sure how. And as for the compute I'm fairly lost, unless there is a data type of math symbols I could just call from.