Help is needed in WindowsForm VC++

I have been trying to get the number of ")" occurred in a system^ string, but keep getting errors.

the problem i'm trying to solve is:
"how many time does ( or ) is occurring in an expression"

tell me the faults in my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
	String^expr = textBox1->Text;
	int count = 0;
	int length1 = textBox1->TextLength;
	int i = 0, b=-1;
	while (length1){
		if ( expr->IndexOf("(")>b || expr->IndexOf(")")>b)
		{
			count++;
		}
		else;
		
	}
	textBox2->Text = System::Convert::ToString(count);
}
Last edited on
length1 is never modified in your while loop, hence you have an infinite loop.

You might break; in the else case.
Topic archived. No new replies allowed.