Need Help with Challenge 1

0 Immanuel Huang · September 4, 2015
Hi everyone! I'm new to programming and I am currently trying to figure out how to add output saying what you are missing in the password.  Any help is appreciated! Thanks!

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>

int main()
{
char password[9];
int dollarSign = 0, num = 0, upperCase = 0;
printf("Please enter a password containing at least one uppercase letter, one number and one dollar sign. (Up to 10 letters)\n\nPassword:");
scanf(" %s" ,password);

for(dollarSign = 0; dollarSign <= 9; dollarSign++){
    if(password[dollarSign] != '$'){
        continue;
    }else{
        for(num = 0; num <= 9; num++){
            if(isdigit(password[num])){
                for(upperCase = 0; upperCase <= 9; upperCase++){
                    if(isupper(password[upperCase])){
                        printf("Good password!");
                        break;
                    }else{
                        continue;
                    }
                    break;
                }
            }else{
                continue;
            }
        }
    }
    break;
}
return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Sandra T · September 10, 2015
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>

int main()
{
char password[9];
int dollarSign = 0, num = 0, upperCase = 0,i;
printf("Please enter a password containing at least one uppercase letter, one number and one dollar sign. (Up to 10 letters)\n\nPassword:");
scanf(" %s" ,password);

for(i= 0; i<= 9; i++){
if(isupper(password)) {upperCase=1;} 
if(isdigit(password)) {num=1;}
if(password=='$')  {dollarSign=1;}
}
if ((upperCase==1) && (num==1) && (dollarSign==1)) {printf("Good password!");
}else{
    printf("Your password don't have a: ");
    if (upperCase==0) {printf("uppercase ");}
    if  (num==0) {printf("num ");}
    if  (dollarSign==0) {printf("dollarSign");}
    }
return 0;
}

I'VE MADE SOME CHANGES, BUT NOW,  THIS PROGRAM SHOWS WHAT YOU ARE MISSING IN THE PASSWORD! ;)
0 Immanuel Huang · September 23, 2015
Thanks!
0 Sandra T · September 23, 2015
You're welcome!
  • 1

C

106,943 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator