Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


c++ simple code, please help :)

hello, i am beginner at this so i need a little help; something wrong with my code; so here is the code:
using namespace std;
int main()
char c;
int i=0;
int n=0;
int open=0;
int close=0;
const int size = 100;
char arr[size];
ifstream f("test.txt");
if (f.is_open()==false)
cout<<"file does not exist."<<endl;
return 1;
if (c==')') {close++; arr[i]==')'; i++;}
if (c=='(') {open++; arr[i]=='('; i++;}

for (int k=0; k<=i; k++)
{if (arr[k]==')' && arr[k+1]=='(') {n==1; break;}};

if(close==open && n==0) cout<<"parentheses are normal";

else cout<<"parentheses are not in good layout";


text file is: "12345 (text)())(text()"
so firstly i need to check if opening parentheses are in the same count as closing parentheses, that works; but i also need to check if somewhere parentheses are like this )( and there i have error; i made that all parentheses are putted into array and into for cycle program checks if after this ) is not this ( and if it is true it makes n=1; and in the end program checks if ) are in the same count as ( and also if n is not 1(''this ) is not before (''); then all is ok
as far as i understand, my mistake is that i guess program doesnt put parentheses into array and cheking into for cycle doesnt work; so if anyone can help me, please share :)
Sign In or Register to comment.