0

Hi yall,

So what my code is supposed to do is basically count the number of paranthesis that the user enters and hit me back with the result.

The code below works perfectly when there are no white spaces in the user's input. But when white spaces are present, It gives me a wrong output.

#include<iostream>
#include <cstdio>
#include <cstdlib> 
#include<iomanip>
#include<cstring>
using namespace std ;

int main()
{

int parancounter =0 ;
char input[100] ;
cout << "Enter input " ;
cin >>input ;
for(int j=0;j<strlen(input);j++)
       {

             if(input[j] == '(')
             {

                parancounter++ ;

             }  

               else if(input[j] == ')')
                 {

                parancounter-- ;
                 } 


       } 
cout << Number of parentheses are " << parancounter  ;
cin.get() ;
}

Thanks in advance for any help you may be able to offer!

Edited by Reverend Jim: Fixed formatting

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by lebronjames
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.