Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    matrixbot
    @matrixbot

    ×€VASTfreedom>Bot > <@gitter_blauelf:matrix.org> The bot again?

    Your are funny being that you are a bot

    Blauelf
    @Blauelf
    You are the one named "matrixbot".
    Nate M
    @WhipStreak23
    Confusing.
    Amin Bashanfar
    @Amin-bash
    Hello guys, I'm new in this group
    I have a question how can I get the sum of an array by digits
    like if I have an array of [1, 2, 3] I want the result to be 6
    but if I have the array [12, 2, 1] the result is not 15 the result is 6
    because I have to count it like this 1 + 2 + 2 + 1 which means 6
    Nate M
    @WhipStreak23
    Could I see your code?
    Amin Bashanfar
    @Amin-bash
    @WhipStreak23 I didn't write the code in C yet
    I made it in JS because this is what I know and then I change it to C code:))
    Blauelf
    @Blauelf
    In JS, using string concatenation/splitting, this is trivial. In C, I would stay in number realm and use integer division/remainder a lot.
    Is this for credit?
    Amin Bashanfar
    @Amin-bash
    @Blauelf yes
    Blauelf
    @Blauelf
    I did division/remainder for isolating the digits. %10 would get me last digit, /10 all digits but the last.
    Amin Bashanfar
    @Amin-bash
    Hello, I think I have an issue with the calculation
    this is the task
    here is my code
    #include <stdio.h>
    #include <cs50.h>
    #include <ctype.h>
    #include <math.h>
    #include <string.h>
    
    int letter;
    int word;
    int sentence;
    
    
    int main(void)
    {
    
    // prompt the user with the question
    
        string article = get_string("What's the article?: ");
    
    // set the length of article
    
        int n = strlen(article);
    
    // add +1 if the article starts with alphanumeric letter
    
        if (isalnum(article[0]))
        {
            word = 1;
        }
    
    // count words
    
        for (int i = 0; i < n;  i++)
        {
            // count letters
    
            if (isalnum(article[i]))
            {
                letter++;
            }
    
            // count words
    
            if (i < n - 1 && isspace(article[i]) && isalnum(article[i + 1]))
            {
                word++;
            }
    
            // count sentences
    
            if (i > 0 && (article[i] == '!' || article[i] == '?' || article[i] == '.') && isalnum(article[i - 1]))
            {
                sentence++;
            }
    
        }
    
    // calculate Coleman-Liau index
    
        // int grade = 0.0588 * (100 * letter / word) - 0.296 * (100 * sentence / word) - 15.8;
        int grade = round(0.0588 * (100 * letter / word) - 0.296 * (100 * sentence / word) - 15.8);
    
    
    // debugger
    
        // printf("Letters: %i\n Words: %i\n Sentences: %i\n", letter, word, sentence);
    
    // print result
        if (grade <= 1)
        {
            printf("Before Grade 1\n");
        }
        else if (grade < 16)
        {
            printf("Grade %i\n", grade);
        }
        else
        {
            printf("Grade 16+\n");
        }
    }
    and here is the error
    image.png
    does anybody know where is the mistake ? :))
    Blauelf
    @Blauelf
    Why would you need the number of alphanumeric characters?
    Again, make those checks less complex, the specification makes it very simple.
    And <=1 does not sound like Before Grade 1
    Amin Bashanfar
    @Amin-bash
    @Blauelf I didn't understand
    Blauelf
    @Blauelf
    1. Use isalpha to count the letters.
    2. The same way, count the space characters. Per problem specification, the number of words is number of spaces plus one.
    3. Count the .?!, no requirements on previous character.
    4. Should be grade < 1, not grade <= 1.
    5. (forgot that first, but important) Make that 100 into 100.0 so that you have floating point division later. Or do a typecast, if you like that more.
    Amin Bashanfar
    @Amin-bash
    @Blauelf yeeeah I got it, thank you bro :))
    22jbinoy
    @22jbinoy
    Hello guys, I am confused about readability. I don't know what kind of codes I should put to make the assignment work. Please help me with readability.
    Blauelf
    @Blauelf
    Most importantly: Don't overcomplicate stuff. According to the specification, all three numbers can be obtained by counting certain characters in the string, no other conditions apply.
    nsoshenko
    @nsoshenko

    @Amin-bash I had a similar mistake: you miss 1 word after the " symbol here:
    if (i < n - 1 && isspace(article[i]) && isalnum(article[i + 1]))
    {
    word++;
    }

    Just change if condition for:
    if (i < n - 1 && (isspace(article[i]) || article[i] == '"') && isalpha(article[i + 1]))
    and try to check it

    Blauelf
    @Blauelf
    Just if (isspace(article[i])) would be sufficient.
    nsoshenko
    @nsoshenko
    @Blauelf don't we miss word "Go!", for example, using such condition?
    No space either before or after
    Blauelf
    @Blauelf
    That's why the word counter should start at 1.
    nsoshenko
    @nsoshenko
    @Blauelf I got what you mean, thanks
    If quote happens in the middle of the sentence, then it always follows a space
    Blauelf
    @Blauelf
    The problem specification just states that everything between spaces can be considered a word.
    biplavc
    @biplavc
    I can't submit my solutions. When I do the check, it says "Looks like check50 isn't enabled for your account yet. Please go to https://submit.cs50.io in your web browser and try again." But over at https://submit.cs50.io, it says "No Submissions. You don't seem to have any submissions yet!" Any idea on how to sort out the issue ?
    Blauelf
    @Blauelf
    @biplavc Is this about cs50x? If so, have you submitted pset0 scratch?
    biplavc
    @biplavc
    @Blauelf I didn't submit the scratch, but the problem was sorted out once I delinked the authorization of cs50 with GitHub, and linked it again .
    Blauelf
    @Blauelf
    @biplavc That also did work for me at some point, back when there were separate repos for check50 and submit50 that would both require authorisation, and one of them went missing in the process. Reset and relinked, accepted the invitations, worked. But from the instructions, it was pretty clear to me something had gone wrong in that case, so I did not wait for check50 to fail. Besides, probably was a very different check50.
    mbrook14
    @mbrook14
    Hello everyone. Just wondering, when we submit our problem sets are we expected to pass all of them? If yes then whats the minimum percentage we must pass with for each problem set. If no then how is the final grade calculated?
    karangargxxx
    @karangargxxx
    I think the minimum is of 70% grade from each pset.
    But try to aim for 100@ cause the reason u r taking this course is for learning and not hte certificate
    Muhammad Idrees
    @muhammadidrees
    Can someone please help me with pset3 trademan I just want to know a condition when the lock_pair skips the middle pair
    Other than that my all checks are okay
    Thank you
    tideman*
    DaithiOLaoi
    @DaithiOLaoi
    Hello all,
    Just wondering - is it possible to complete Tideman without using recursion? I've hit a mental block using nested loops
    José Carlos Bedoya Rivera
    @jcbdark
    from caesar this is my code

    include <cs50.h>

    include <ctype.h>

    include <string.h>

    include <stdio.h>

    include <stdlib.h>

    int main(int argc, string argv[])
    {
    int key = atoi(argv[1]);
    if (argc != 2 )
    {
    printf("Usage: ./caesar key\n");
    return 1;
    }
    string plaintext;
    plaintext = get_string("plaintext: ");
    printf("ciphertext: ");

    for(int i = 0, n = strlen(plaintext); i < n; i++)
    {
        if(isupper(plaintext[i]))
        {
            printf("%c",((plaintext[i]-'A') + key )% 26 + 'A');
        }
        else if(islower(plaintext[i]))
        {
            printf("%c",((plaintext[i]-'a') + key) % 26 + 'a');
        }
        else
        {
            printf("%c",plaintext[i]);
        }
    }
    printf("\n");

    }

    what is the error in check50
    Blauelf
    @Blauelf
    Performing atoi(argv[1]) before testing argc? Asking for trouble.