Challenge 1 I have no clue why it wont work HELP!!!!

+3 Kent Spence · August 10, 2015
Hey hers my code for the first challenge I'm not sure why it doesn't work correctly there is something going wrong in the loop section I believe but it just doesn't want to work correctly grrr help please :)





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

int main()
{
    char passWord[30];
    int upper , lower , digit , symbol , i;
    upper = lower = digit = symbol = 0;
    //for diagnostics
    printf("upper = %d, lower = %d digit = %d symbol = %d\n", upper, lower, digit, symbol);


    printf("enter a password that contains a lower case letter,\n");
    printf("an upper case letter, a number, and a symbol.\n");
    scanf(" %s", passWord);

for(i=0; i<=30; i++ ){
 if (isupper(passWord)){
    upper++;
 }
 if (islower(passWord)){
    lower++;
 }
 if (isdigit (passWord)){
    digit++;
 }
 if (passWord == '!' || passWord == '@' || passWord == '#'
    || passWord == '$' || passWord == '%' || passWord == '^'
    || passWord == '&'|| passWord == '*' || passWord == '-'
    || passWord == '+'){
    symbol++;
  }
 }



//for diagnostics
printf("upper = %d, lower = %d digit = %d symbol = %d", upper, lower, digit, symbol);

if(upper>=1 && lower>=1 && digit>= 1 && symbol>= 1){
    printf("\n\nThat is a strong password you've got there");
}
else{
    printf("\n\nthat is a weak password");
}

    return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Amisha Singh · August 14, 2015
Your upper bound for the for loop is 30 which may or may not be true for the password entered by the user, in the sense that the user could enter a password shorter than 30 characters. Use strlen() fn to calculate the length of the string first the use that in the loop.
0 c student · August 10, 2015
if i enter AbC!23, what is at elements 6 - 30?
0 Sha Kal · August 10, 2015
if (isdigit (passWord(i) )); 

Same for upper, lower and symbol.
0 Kent Spence · August 11, 2015
Cheers @Sha Kal :D
  • 1

C

106,972 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator