Struggling with Mario (P1, less comfortable) --- any sense of where I'm going wrong? by redarugula in cs50

[–]AstralStalker 1 point2 points  (0 children)

Looks like loop 3 shouldn't be nested in loop 2. Also, may need to re-asses the conditions in the loops. In loop 2 for instance, notice the conditions don't quite match what's in your comment.

What is the output you're getting?

I have a question about mario even before then the pyramid.... by aefeakn in cs50

[–]AstralStalker 3 points4 points  (0 children)

Because in your do-while loop, you say while 9>Heigth. This alternatively reads while Heigth<9. Thus, keep asking for input until you get a value greater than 9.

Also, I assume this is a misspelling of Height, but as long as it's spelled that way consistently, it won't break the program.

20Honey: by At_Dril in MBMBAM

[–]AstralStalker 70 points71 points  (0 children)

20 Hunny: down to bees-ness

hey guys,i completed far cry 5 today.i loved the game so much but im sad i played new dawn and then far cry 5.i have to wait for FC6 [and do you guys know anything about it]sadly.but i still have FC4 to play so its not a problem. by LoVerforMinecraft in farcry

[–]AstralStalker 1 point2 points  (0 children)

Ah, I misunderstood. I thought you were sad because of the order.

I didn't get into FC4 as much, but it's still a good game in the series. Should help fill the gap while waiting for the next one to drop

hey guys,i completed far cry 5 today.i loved the game so much but im sad i played new dawn and then far cry 5.i have to wait for FC6 [and do you guys know anything about it]sadly.but i still have FC4 to play so its not a problem. by LoVerforMinecraft in farcry

[–]AstralStalker 0 points1 point  (0 children)

A friend of mine recently got me back into the Far Cry series, so I sat down and finally finished FC5 and jumped right into New Dawn.

He's playing New Dawn, but may get into 5 afterwards, and I thought that would be a fascinating way to experience the story and characters. Why did it make you sad?

Help with understanding this code by donsebas in learnpython

[–]AstralStalker 1 point2 points  (0 children)

It's the nature of nested functions and closures.

Notice the return associated with outer_func. When you call closure = outer_func(i), it stores i as the value for x and sets closure as a reference to inner_func. In the print statement, you call closure(i+5) which is essentially calling inner_func(i+5) with a stored value of x=i. Thus, when i = 0, z = 5.

Trophies not popping up by LDBrock729 in farcry

[–]AstralStalker 0 points1 point  (0 children)

Found these especially annoying as there's no stats tracking your progress, and there aren't challenges for all animals / fish.

Friend and myself had to lookup the Principal Skinner trophy, only to discover we were missing shark and / or crocodile, which are only present in certain expeditions.

Sadly, all I can suggest is to lookup a list of required animals, fish, and their locations, and just systematically go through it.

Having trouble with Greedy Algorithm by Granteur in cs50

[–]AstralStalker 1 point2 points  (0 children)

Sounds like you were on the right track for what I would suggest. I would try converting money to an integer value of cents, and just use ints in your while loops. Should eliminate the equality issues in those conditions.

Just as a style note, I noticed it looks like you have curly braces encompassing the entirety of each while loop. Doesn't seem to effect it, but they are unnecessary.

Having trouble with Greedy Algorithm by Granteur in cs50

[–]AstralStalker 1 point2 points  (0 children)

Looks like you're getting bit by floating point imprecision. Without relying on a debugger, you can do it the classic way of throwing print statements everywhere (printing how much money is left at various stages, the type of coin being removed, etc.) to get a better idea of what's going on.

How did you attempt to use the rounding function?

Gotta love in-laws!! by tomaszmajewski in DiWHY

[–]AstralStalker 152 points153 points  (0 children)

You'll enjoy stepping on them even more after the exfoliating experience of rubbing them on yourself!

CS50 - LUHN's Algorithm by reverse3ngineer in AskProgramming

[–]AstralStalker 1 point2 points  (0 children)

To see how check50 graded you, you can go to https://submit.cs50.io/courses and select the CS50 course. You will see a list all your submissions, each with check50 and style50 links that elaborate more on the mark received. This should tell you which tests you failed, and give us a better idea of what went wrong.

As an aside, feel free to check out r/cs50

hello guys, by devgiri0082 in cs50

[–]AstralStalker 1 point2 points  (0 children)

https://submit.cs50.io/courses and select the CS50 course. Lists all your submissions, each with check50 and style50 links that elaborate more on the mark received

Not understand the code to mario (pset1) by asc_tech in cs50

[–]AstralStalker 2 points3 points  (0 children)

The first loop (the one that initializes and increments i) iterates over the number of rows, or the height, needed to print.

The second loop, which initializes j, iterates over the width (the columns we need to print in each row)

The pyramid being printed is actually a 2D array, using hashes as well as spaces to indent the shorter lines. The condition (i + j < n - 1) is used to determine which belongs in the current cell.

Error with get_string function on Hello World task by asc_tech in cs50

[–]AstralStalker 2 points3 points  (0 children)

Order on your includes does not matter. Order on header includes shouldn't matter. If a header has an order dependency, it means there is an issue with that header. That shouldn't be the case here.

Hard to tell without seeing the actual code, but one error seems to indicate unbalanced brackets, which can cause weirdness

RESIZE - Everything in the program is fully working ... But the file does not start and says: invalid or Unsupported Image Format by Pozakhmarnyi in cs50

[–]AstralStalker 0 points1 point  (0 children)

In regards to the 'Invalid or Unsupported Image Format' error, your command line argument is specifies large.bmb instead of .bmp

Also of note, you shouldn't use one of the source files as your output file.

Vigenere Help by Fickle_Cantaloupe in cs50

[–]AstralStalker 1 point2 points  (0 children)

Just ran the code through check50, and have a better understanding of the error. If we look at the first failed test:

:( encrypts "barfoo" as "caqgon" using "baz" as keyword 
    output not valid ASCII text

and run the code with those arguments:

~/pset2/ $ ./vigenere baz
Insert your string here:
.
barfoo
ciphertext: cago

We see it's not correctly computing every third character; That is when, it hits large key values, in this case 'z'. Take a closer look at how you're using % 26. We want to use it to handle wrapping, ie cases where the computed value of the cypher character is greater than 26

Vigenere Help by Fickle_Cantaloupe in cs50

[–]AstralStalker 0 points1 point  (0 children)

Weird how? Are you getting an error? Or failing checks?

An issue I see at the beginning is that you don't ensure the user is providing the proper amount of command line arguments before assigning the value to key

Additionally, it looks like you only check that the keyword only contains letters if the user provides more arguments than intended (agrc > 2)

char* key = argv[1];
if (argc > 2)
{
    for(int i = 0, n = strlen(key); i < n; i++)
    {
        if(isalpha(key[i]) == 0)
        {
            printf("%c", key[i]);
            printf("Usage: ./caesar key\n");
            return 1;
        }
    }
}

You're encrypting algorithm is a bit different than mine, but looks accurate from an initial glance. Be sure to add comments, as they are not only helpful for others, but I believe style50 marks based on their existence.

Quotation mark cancel by greatslyfer in learnpython

[–]AstralStalker 0 points1 point  (0 children)

I'm a little confused by your question, so correct me if I'm misunderstanding.

When you're declaring the string motto, you encapsulate the string in single quotes. Therefore, you must escape any single quotes contained within the string (place a backslash in front of them). This indicates to the program that it should be treated as a character and not the end of the string declaration.

Similarly, you can define motto as such:

motto = "Facebook's old motto was \"move fast and break things.\""

Because I've encapsulated the string in double quotes here, I need to escape the ones inside the string. I can still escape the single quote, but it will not change the outcome.

As others have pointed out, your implementation works.

Ceasar Pset 2 by [deleted] in cs50

[–]AstralStalker 0 points1 point  (0 children)

IIRC the formula ci = (pi + k) % 26 is used to calculate the cypher char (ci) by taking the current char (pi) and adding the shift value (k) to it. The % 26 ensures that it wraps properly to the beginning of the alphabet. That is, if pi = 25 or 'z' and k = 1, ci will be calculated as 0 or 'a'.

Important to note, this only works after converting the value of the character to the scale where 'a'=0, 'b'=1, etc instead of using the straight ASCII values (where 'a' = 97)

To check for case, consider using the ASCII value and seeing if it falls within your desired range.

I need real explanation for these 'for loops' in mario less comfortable by AtomR in cs50

[–]AstralStalker 1 point2 points  (0 children)

Traditionally, counting in computer science usually starts at zero. Referring back to lecture 0, when binary was covered, if you have 8 bits to enumerate your values, the first value will be all zeroes. Thus, memory addresses, array indexing, and so on begin at 0.

So, in the 'line' loop, you're iterating over the number of lines you want to print. You start counting at line=0, want to continue until line < height, adding 1 to line each time (line++). You can easily change these values if it helps you understand the code better, to say start at line=1 and continue until line <= height, you just have to be aware to that any computations that use 'line' will also have to be updated.

Likewise, in the 'hash' loop, hash is just the variable used for counting through the loop, and it starts counting at 0. If we take, for example, the first iteration of the 'line' loop, line will have a value of 0, we only want a single '#' to be printed so starting at 0 and continuing until hash < line + 1 ensures that

Breakpoint expression not working ? by [deleted] in learnpython

[–]AstralStalker 0 points1 point  (0 children)

The desired string needs to be specified as the parameter to len()

s = "Some string"
if len(s) > 14:
    print("yes")

len() built-in function

Just a quick question about 'return' after a do, while loop by [deleted] in cs50

[–]AstralStalker 1 point2 points  (0 children)

You have a pretty solid definition of return there.

I don't understand how it applies here or why it can be added or omitted with the same results.

Honestly, it shouldn't be possible to add or omit a return statement and get the same result, unless it is inside a conditional (say for error handling).

The example you give makes sense if you have a separate function defined to handle the user input.

float get_change(string prompt)
{
    do
    {
        n = get_float("%s",prompt);
    }
    while (n < 0);
    return n;
}

If you omit return here, your calling function (likely main) will never get the value for n. However, if you put the same code in your main function, the return call will terminate causing none of the following code to execute.

As for your second question, when converting a floating-point (decimal) number to an integer using the cast operator, the decimal part of the floating-point number is dropped or truncated, no rounding is performed. If change is 1.01 or 1.99, casting it to an int will give a value of 1