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!

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.