Currently, my code takes in a string from a user, checks if the paranthesis are
ID: 3551426 • Letter: C
Question
Currently, my code takes in a string from a user, checks if the paranthesis are ballanced (as defined by my class) and also returns the variable from my line (also from my class). All I need help with at this point is that I'd like to change this code to read in strings from a text file (each line is a string), print out the line, if the parenthese are balanced (true or false), and then the variables. I want it to quit when there are no more lines to read.
int main(){
string s;
cout<<"Enter strings(q to quit): ";
while(getline(cin,s)){
if(s=="q" || s=="Q")
break;
if(checkBalancedParentheses(s)){
cout<<"Parentheses balanced. ";
}else{
cout<<"Parentheses not balanced. ";
}
cout<<"Proccesed string: "<<processString(s)<<endl<<endl;
}
return 0;
}
Explanation / Answer
int main(){
string s;
cout<<"Enter strings(q to quit): ";
ifstream fin;
fin.open("file.txt");
while(getline(fin,s)){
if(s=="q" || s=="Q")
break;
if(checkBalancedParentheses(s)){
cout<<"Parentheses balanced. ";
}else{
cout<<"Parentheses not balanced. ";
}
cout<<"Proccesed string: "<<processString(s)<<endl<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.