Strong password i am unable to find mistake please help!

q;Strong Password | HackerRank

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l,i,a=0,b=0,c=0,d=0,S=0,j,s1=0;
    string s;
    cin>>l;
    for(j=0;j<l;j++)
    {
    cin>>s[j];
    }
    for(i=0;i<l;i++)
    {
     if(isalnum(s[i]))
     {
         if(isupper (s[i]))
         {
           if (a=1)
            {
                continue;
            }
            else
            {
                a++;
            }
         }
         if(islower (s[i]))
         {
              if (b=1)
            {
                continue;
            }
            else
            {
                b++;
            }
         }
         if(isdigit (s[i]))
         {
              if (c=1)
            {
                continue;
            }
            else
            {
                c++;
            }
         }
     }
     else
     {
          if (d=1)
            {
                continue;
            }
            else
            {
                d++;
            }
     }
    }
        S=a+b+c+d;
     if(S=4)
     {
         if(l<6)
         {
            cout<<6-l; 
         }
         else
         {
             cout<<0;
         }
     }
     else
     {
         s1=(4-S);
         if(l<6)
         {
             if((s1+l) < 6)
             {
              cout<<(6-l);   
             }
             else
             {
                cout<<s1;
             }
         }
         else
         {
             cout<<s1;
         }
     }
return 0;    
}

The code is perfect. Just a silly error where ever you used if statement ->
replace if(x=1) by (x==1). ‘==’ is used to compare.
except this i have run this code and it is working fine good work. Hope this help

1 Like

now this code is giving Segmentation Fault why

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l,i,a=0,b=0,c=0,d=0,S=0,j,s1=0;
    string s;
    cin>>l;
    for(j=0;j<l;j++)
    {
    cin>>s[j];
    }
    for(i=0;i<l;i++)
    {
     if(isalnum(s[i]))
     {
         if(isupper (s[i]))
         {
           if (a==1)
            {
                continue;
            }
            else
            {
                a++;
            }
         }
         if(islower (s[i]))
         {
              if (b==1)
            {
                continue;
            }
            else
            {
                b++;
            }
         }
         if(isdigit (s[i]))
         {
              if (c==1)
            {
                continue;
            }
            else
            {
                c++;
            }
         }
     }
     else
     {
          if (d==1)
            {
                continue;
            }
            else
            {
                d++;
            }
     }
    }
        S=a+b+c+d;
     if(S==4)
     {
         if(l<6)
         {
            cout<<6-l; 
         }
         else
         {
             cout<<0;
         }
     }
     else
     {
         s1=(4-S);
         if(l<6)
         {
             if((s1+l) < 6)
             {
              cout<<(6-l);   
             }
             else
             {
                cout<<s1;
             }
         }
         else
         {
             cout<<s1;
         }
     }
return 0;    
}

This is wrong, for taking string input you just need to use
cin>>s
remove the entire for loop and replace it with cin>>s;

2 Likes

yaa…string is provided as an argument to the function in that question that is why I missed it.

ya it worked thanks everyone!