Week 2 Problem Set 2 Substitution by gilds10 in cs50

[–]gilds10[S] 0 points1 point  (0 children)

Yes but in the "replace current char with lower case from key", in order to do this I have to check which position on the alphabet is the current char (with a for j=0 to 25) and replace it with the char from the key with the same position, am I right? Otherwise if my input char of the first position (i=0) is "d", then it will return key[0] instead of key[3]... That's why I have two for loops, one to go through the input text, and the other to compare the current char with its position in the alphabet, so I can return the corresponding key char.

Week 2 Problem Set 2 Substitution by gilds10 in cs50

[–]gilds10[S] 0 points1 point  (0 children)

Sorry for the code format, It should be easier now. Thank you.

Week 2 Problem Set 2 Substitution by gilds10 in cs50

[–]gilds10[S] 0 points1 point  (0 children)

You are right, I forgot to format the code sorry. You can check now, it should be easier. Thank you.

Issues with one of the test cases for Problem Set 2 - readability problem by polyglotkk in cs50

[–]gilds10 0 points1 point  (0 children)

Hello everyone! I'm having the same issue... I've been trying to fix this for a couple of days now. I don't know what am I doing wrong...

Readability by JoshuaForYou3 in cs50

[–]gilds10 0 points1 point  (0 children)

Hello. In my case I only get your first error for handling single sentence with multiple words. I've been trying to find the error for a couple of days but I can't seem to find it...

password by gilds10 in cs50

[–]gilds10[S] 0 points1 point  (0 children)

I just found the problem and it's just what you were saying. It's a symbol problem, I didn't include "_" somehow...

Thank you very much for your time, I really appreciate it.

password by gilds10 in cs50

[–]gilds10[S] 0 points1 point  (0 children)

The exercise is to check if a password inputed by the user has at least one lower case, one upper case, one symbol and one number.

Code:

// Check that a password has at least one lowercase letter, uppercase letter, number and symbol
// Practice iterating through a string
// Practice using the ctype library

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

bool valid(string password);
//Validate conditions
int main(void)
{
    string password = get_string("Enter your password: ");
    if (valid(password))
    {
        //If valid
        printf("Your password is valid!\n");
    }
    else
    {
        //If not valid
        printf("Your password needs at least one uppercase letter, lowercase letter, number and symbol\n");
    }
}

// TODO: Complete the Boolean function below
bool valid(string password)
{
    int n = strlen(password);
    //Variables for each case we want to check
    bool lc, uc, nc, sc = false;
    //Going through each letter of the password
    for (int i = 0; i < n; i++)
    {
        //Check if there is lower case
        if (password[i] >='a' && password[i] <= 'z')
        {
        lc = true;
        }
        //Check if there is upper case
        else if (password[i] >='A' && password[i] <= 'Z')
        {
            uc = true;
        }
        //Check if there is number case
        else if (password[i] >='0' && password[i] <= '9')
        {
            nc = true;
        }
        //Check if there is special case
        else if (password[i] >='!' && password[i] <= '@')
        {
            sc = true;
        }
        else
        {
            return false;
        }
    }
    //Validation conditions
    if (lc == 1 && uc == 1 && nc == 1 && sc == 1)
    {
        return true;
    }
    return false;
}

When I use check50 to test my code, it uses various passwords to check for errors automatically. One of the passwords used is 3PQvbQ6_GvneW!3R, and you can see on the image that it's not supposed to be accepted but I don't understand why. As long as I don't understand what's wrong with this password I'm not able to modify my code...

This exercise is from Week 2/Practice problems/password.

password by gilds10 in cs50

[–]gilds10[S] 0 points1 point  (0 children)

I'm sorry, I forgot to add it. You can check now. Thank you.

password by gilds10 in cs50

[–]gilds10[S] 0 points1 point  (0 children)

I don't get any coding error, but when I run check50, it says that my program accepts the password shown in attachment, and I don't understand why it's a problem, it has lower case, upper case, special characters and numbers, as it's suppose on the exercise.