ashley11

i have a problem to sum up the value.
for example:
in my richtextbox1:
0.94
0.83
1.67
0.50
0.67
1.25
0.98

now i wan to total up the value.
if the value is less than 1 , then total is 5.
if the value is greater than 1, then total is 2.
below are my coding, but cannot work.

``````  int count = 0;

double liftV = richTextBox24.Lines.Length;

if (liftV <1.00)
{
count++;

}
textBox5.Text=count.ToString();
``````

hope someone can help me..

abelLazm 183

Code to sum up

``````//Your Code
double sum=0;
int length=richTextBox1.Lines.Length;
for(int i=0;i<length;i++)
{
sum+=Double.Parse(richTextBox1.Lines[i]);
}
if(sum<1)
{
}
else
{
}

abelLazm 183

``````//Your Code
double sum=0;
int length=richTextBox1.Lines.Length, totalGreater=0, totalsmaller=0;
for(int i=0;i<length;i++)
{
//sum+=Double.Parse(richTextBox1.Lines[i]);
if(Double.Parse(richTextBox1.Lines[i])>=1)
totalGreater++;
else
totalSmaller++;

}
MessageBox("Total values less than 1 are:"+totalSmaller+"\n Total values greater than equal to 1 are:"+totalGreater);

ashley11

i had try your code, but it show me a error which is input string was not in a correct format.
may i know any wrong that i did?

abelLazm 183

This Code is Working Fine.... Check the input you are giving in the richTextBox1

``````double sum = 0;
int length =   richTextBox1.Lines.Length, totalGreater = 0, totalSmaller = 0;
for (int i = 0; i < length; i++)
{
//sum+=Double.Parse(richTextBox1.Lines[i]);
if (Double.Parse( richTextBox1.Lines[i]) >= 1)
totalGreater++;
else
totalSmaller++;

}
MessageBox.Show("Total values less than 1 are:" + totalSmaller + "\n Total values greater than equal to 1 are:" + totalGreater);

ashley11

``````string b = txtTotalItems.Text;
double tt = Double.Parse(b);
double a;
double conf;
double lift;

richTextBox23.Clear();
richTextBox24.Clear();
richTextBox20.Clear();

for (int i = 0; i < list8.Count; i++)
{
double wee = list8[i];
a = (wee / tt) * 100;
richTextBox3.AppendText(string.Format("{0:n2}", a) + "\n");

double SuppA = list9[i];
conf = a / (SuppA / tt);
richTextBox2.AppendText(string.Format("{0:n2}", conf) + "\n");

double SuppB = list10[i];
lift = conf / (SuppB / tt) / 100;
richTextBox1.AppendText(string.Format("{0:n2}", lift) + "\n");``````

code above are my calculation part. now i wan to sum up the total in the rich textBox1.
when i try your coding, then show me the error which i mentioned just now. how to i correct it?

abelLazm 183

can you please tell where you want to add the above mentioned code?

ashley11

``````string b = txtTotalItems.Text;
double tt = Double.Parse(b);
double a;
double conf;
double lift;

richTextBox23.Clear();
richTextBox24.Clear();
richTextBox20.Clear();

for (int i = 0; i < list8.Count; i++)
{
double wee = list8[i];
a = (wee / tt) * 100;
richTextBox3.AppendText(string.Format("{0:n2}", a) + "\n");

double SuppA = list9[i];
conf = a / (SuppA / tt);

richTextBox2.AppendText(string.Format("{0:n2}", conf) + "\n");

double SuppB = list10[i];
lift = conf / (SuppB / tt) / 100;

richTextBox1.AppendText(string.Format("{0:n2}", lift) + "\n");
}

double sum = 0;
int length = richTextBox24.Lines.Length, totalGreater = 0, totalSmaller = 0;
for (int i = 0; i < length; i++)
{
//sum+=Double.Parse(richTextBox1.Lines[i]);
if (Double.Parse(richTextBox24.Lines[i]) >= 1)
totalGreater++;
else
totalSmaller++;

}
MessageBox.Show("Total values less than 1 are:" + totalSmaller + "\n Total values greater than equal to 1 are:" + totalGreater);
}``````

may i know any mistake with it?

ashley11

``````string b = txtTotalItems.Text;
double tt = Double.Parse(b);
double a;
double conf;
double lift;

richTextBox23.Clear();
richTextBox24.Clear();
richTextBox20.Clear();

for (int i = 0; i < list8.Count; i++)
{
double wee = list8[i];
a = (wee / tt) * 100;
richTextBox3.AppendText(string.Format("{0:n2}", a) + "\n");

double SuppA = list9[i];
conf = a / (SuppA / tt);

richTextBox2.AppendText(string.Format("{0:n2}", conf) + "\n");

double SuppB = list10[i];
lift = conf / (SuppB / tt) / 100;

richTextBox1.AppendText(string.Format("{0:n2}", lift) + "\n");
}

double sum = 0;
int length = richTextBox1.Lines.Length, totalGreater = 0, totalSmaller = 0;
for (int i = 0; i < length; i++)
{
//sum+=Double.Parse(richTextBox1.Lines[i]);
if (Double.Parse(richTextBox1.Lines[i]) >= 1)
totalGreater++;
else
totalSmaller++;

}
MessageBox.Show("Total values less than 1 are:" + totalSmaller + "\n Total values greater than equal to 1 are:" + totalGreater);
}``````

may i know any mistake with it?

abelLazm 183

in line# 30 run the loop to i<length-1 because you append "\n" at the end that is why your last item in the richTextBox1 is an empty string which is causing error

Saikalyankumar -2

Apart from the Point said by abelLazm remaining all is fine, i checked it out.

ashley11

thanks. i get it.