challenge 1

+1 shivam mahajan · December 18, 2014

well this seemed to work for me...plz tell me if u have any suggestions ! 


#include<stdio.h>
#include<ctype.h>




int main(void)
{
   char password[15] ;
   int i;
   printf("choose a password\n");
   scanf("%s",password);
   i=0;

   while(!isupper(password) && password!='\0')
   {
       i++;
    }

    if( password=='\0')
        {
            printf("your password sucks");
        }
     else
     {
         i=0;

        while(!isdigit(password) && password!='\0')
          {

              i++;
          }

          if(password=='\0')
          {
              printf("your password sucks");
          }
          else
          {
              i=0;
            while(password!='\0')
            {
              if(password=='$')
              {
                  printf("your password is fine\n");
                  break;
              }

              else
              {
                  i++;

              }

            }
            if(password=='\0')
            {
                printf("your password sucks\n");
            }



          }
          }







}



Post a Reply

Replies

Oldest  Newest  Rating
+1 Steven the awesome · December 18, 2014
I don't want to sound like a asshole everywhere, but could you please use the code tags around your'e source code?  
0 shivam mahajan · December 18, 2014
sry..i did'nt really get u ? ..what code tags are you talking about ? m pretty new to coding so can u please expand ?
0 Sagar Bhandari · December 20, 2014
I think he meant writing your source code in the "code" option in the toolbar.

And as for your program: It didn't work in my PC!.  You should use loop to get one string at a time and testing it for uppercase, lowercase, number and dollar/special characters!
/images/forum/upload/2014-12-20/e3d36c01137dd94b6dbbf2eecab5f3dd.JPG
0 c student · December 20, 2014
looks and probably is too complex.  the best solutions are the most simplest.  your main also lacks a return value for its return type.
0 Steven the awesome · December 20, 2014
@Sagar Bhandari is right I was talking about that, it makes your'e code way better to read. You see :)


#include<stdio.h>
#include<ctype.h>




int main(void)
{
char password[15] ;
int i;
printf("choose a password\n");
scanf("%s",password);
i=0;

while(!isupper(password) && password!='\0')
{
i++;
}

if( password=='\0')
{
printf("your password sucks");
}
else
{
i=0;

while(!isdigit(password) && password!='\0')
{

i++;
}

if(password=='\0')
{
printf("your password sucks");
}
else
{
i=0;
while(password!='\0')
{
if(password=='$')
{
printf("your password is fine\n");
break;
}

else
{
i++;

}

}
if(password=='\0')
{
printf("your password sucks\n");
}



}
}







}
0 KEVIN K P · December 21, 2014
Have a look at this guys


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int len,i;
    int upper=0;
    int digit=0;
    int dollar=0;
    int lower=0;
char password[16];
puts("enter a password with atleast one uppercase,one lowercase,one digit,one $ symbol");
puts("Password length must be minimum 8 characters and maximum 16 characters");
gets(password);
len=strlen(password);
if(len>7&&len<16){
    for(i=0;i<len;i++){
        if(isdigit(password)){
            digit++;
        }
        if(isupper(password)){
            upper++;
        }
        if(islower(password)){
            lower++;
        }
        if(password=='$'){
            dollar++;
        }

    }
    if(digit>0&&upper>0&&dollar>0&&lower>0){
printf("You have got a strong password\n");
printf("AWESOME!!!!");
    }
    else{
         printf("WTF Password SUCKS!!!!");
    }
}
else{
    printf("WTF Password SUCKS!!!!");
}
return 0;
}


  • 1

C

107,022 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator