I'm creating a form that would store monthly sales amounts. The user would hit a submit button and those amounts would be stored in an Array.
There is then a Total Button that would be clicked, and call a method that would total the amounts from the Array.
So far I have two issues (that I know of): First, I'm still unsure of the proper format to call my method. Right now VS doesn't like my variable "x". I wasn't sure what to use, so I just stuck one in there. Second, the code for summing my Array is not right either. VS doesn't like my "index" variable.
I've tried to note the problem areas in the code. Sorry for the lengthy post and the ignorant questions.
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void submitButton_Click(object sender, EventArgs e)
{
//creating an array
const int SIZE = 12;
decimal[] amountsArray = new decimal[SIZE];
amountsArray[0] = decimal.Parse(JaninputBox.Text);
amountsArray[1] = decimal.Parse(FebinputBox.Text);
amountsArray[2] = decimal.Parse(MarinputBox.Text);
amountsArray[3] = decimal.Parse(AprinputBox.Text);
amountsArray[4] = decimal.Parse(MayinputBox.Text);
amountsArray[5] = decimal.Parse(JuninputBox.Text);
amountsArray[6] = decimal.Parse(JulinputBox.Text);
amountsArray[7] = decimal.Parse(AuginputBox.Text);
amountsArray[8] = decimal.Parse(SepinputBox.Text);
amountsArray[9] = decimal.Parse(OctinputBox.Text);
amountsArray[10] = decimal.Parse(NovinputBox.Text);
amountsArray[11] = decimal.Parse(DecinputBox.Text);
TotsalesButton.Enabled = true;
}
private void TotsalesButton_Click(object sender, EventArgs e)
{
// calling the method to total amounts from array
TotalIt(decimal x); **//<-- VS doesn't like this**
AvgsalesButton.Enabled = true; //enabling avg sales button
}
private void TotalIt(decimal[] amountsArray)
{
decimal sum; // variable to hold total
// method for totaling array data
for (decimal index = 0; index < amountsArray.Length; index++)
{
sum += amountsArray[index]; **//<-- Doesn't like "index"** here.
}
}
}
}