Challenge #1

0 Mohamed Nana'a · September 26, 2014

#include<ctype.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
main(){
while(1){
int conditions=0;
int conditions2=0;
int i;
char password[5];

printf("\nenter the password(5 characters) :\n");
scanf(" %s/n",&password);

for(i=0;i<=strlen(password);i++){
   if(isupper(password)){
    conditions=1;
   }
}

for(i=0;i<=strlen(password);i++){
   if(isdigit(password)){
    conditions2=1;
   }
}
if(conditions==1 && conditions2==1){
    printf("GOOD JOB YOU MADE IT");

}else{
printf("\nYou need to use a number and an upper case character\n");
}
}
}


so... someone can tell me if i am right? :D

Post a Reply

Replies

Oldest  Newest  Rating
0 Franz Schmidt · September 27, 2014
You are right in most points, Kroothushas ...
but he didn't do
conditions++;
he did
conditions = 1;
so you can have several numbers or uppercases the condition will always be 1 if you have at least one char of it.

If you just set the conditions to 1 i would recommend to use bool vars, they only have true or false.
e.g.:

for (int n = 0; n < strlen(password); n++){
if (isupper(password[n])){
condition_upper = true;
}
       else if(isdigit(password[n])){
               condition_digit = true;
       }
}

And I think he knows that isupper and isdigit just check single chars not arrays
The problem is the codetags don't recognize /[i/] this cause of bbcodes
For this reason use n as counter
0 Mohamed Nana'a · September 28, 2014
thanks guys will try to be better next time :)
  • 1

C

106,993 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator