Hello again,
I am having some issues adding up numbers. Here is the logic:
I have a long string that is in the format name|1|2|3 etc.
I am trying to add the sum of all the numbers following the name. So, from the above example, I am looking for the number 6, 1+2+3.
At first I was thinking that, since the first value is a name, that was what is giving me the cannot convert type string to int, but then I thought that this error would happen after compiling and not before.
I was able to determine the number of grades, successfully, in the string, since that will not be constant with this code:
string temp = StudentsListBox.SelectedItem.ToString();
// Determine Number of Grades
int totalIndexes = 0;
int i = 0;
while (temp.IndexOf("|",i) != temp.LastIndexOf("|"))
{
i = temp.IndexOf("|", i);
// Prevent infinite loop
i++;
totalIndexes++;
}
totalIndexes += 1;
ScoreCountTextBox.Text = totalIndexes.ToString();
//------------Having Issues Here------------
// Determine Total Grade
int totalGrade = 0;
int p = 0;
int i = 0;
while (temp.IndexOf("|", i) != temp.LastIndexOf("|"))
{
i = temp.IndexOf("|", i);
p = temp.IndexOf("|", i+1);
totalGrade += (int)temp.Substring(i + 1, p - i).ToString();
// Prevent infinite loop
i = i + 1;
}
Thank you for taking the time to read this.