Here the snippet:
As you can see, the program looks through a string as it is being typed and output the number sub-series in the string that start with 'a' end with 'b' and have no 'c' in the middle. So the string "dsacbsabxbxxa" would return 2 (for "ab" and "abxb").Code:#include <iostream.h> #include <stdlib.h> #include <conio.h> char ch; //Holds current input for evaluation. int a; //Holds number of chain starts. int b ; //Holds number of chain ends. int sum ; //Sum of chains. void main() { a = 0; b = 0; sum = 0; While(ch != '.') { ch = getch(); if (ch == 'a') a++; if (ch == 'b') b++; if (ch == 'a' && b > 0) { sum = sum + (a*b); b = 0; } if (ch == '.' && ch == 'c') { sum = sum + (a*b); a = 0; b = 0; } cout << "\n << sum; } system("PAUSE"); }
This code won't compile in Dev-C++ with multiplile errors.
What's the problem?



LinkBack URL
About LinkBacks



, isn't in yet. 