Hot answers tagged

3 votes
Accepted

What's my error?

Your problem lies with the / operator. Because the RGB values and the denominator are all integers, integer division is being performed and the fractional remainder is dropped instead of being passed ...
user avatar
  • 930
3 votes
Accepted

PSET4 resize (less) check50 error

Well, your description is sort of right. The image size is incorrect. When I ran the code, the headers are fine. The problem is that the image data that's being generated is too large by roughly ...
user avatar
  • 63.4k
3 votes

Pset6 similarities less substrings I get wrong output

Look at your asub and bsub right before returning an answer. (you can use print to see what they are). Looks like they're getting re-defined for each i rather than accumulating a list of all possible ...
user avatar
  • 133
2 votes

Pset6 similarities less substrings I get wrong output

You have some substrings that are shorter than the others because there are no n characters left at index i. How many substrings of length n can you have in a string of length len(a)? n is part of ...
user avatar
  • 20.7k
2 votes
Accepted

Resize less confortable pset3. Result seems ok if open as hexadecimal but the print result is cropped

In your example, the bitmap is scaled by a factor of 2 horizontally, but 3 vertically. Since you write an output line on reading, and additionally n output lines in a loop, you write n+1 output lines ...
user avatar
  • 20.7k
2 votes

PSET 1 Can't implement loop at the prompt

First of all, "recursive" means something that calls itself repeatedly. You mean that you can't get the loop to repeat. Think about the condition clause. while (n < 0 && n > 8)...
user avatar
  • 63.4k
2 votes
Accepted

running into a do...while loop issue

That works fine and will reprompt for any value greater than 23. Is it possible that you haven't run make since your last change? You have to recompile (using make mario) every time you change & ...
user avatar
  • 18.3k
2 votes
Accepted

Another question about how my 'for' parameters are affecting my output?

If it is for a certain number of iterations, and the counter does not matter, I'd recommend using one of the two forms for (int counter = 0; counter < repeats; counter++) or for (int counter = ...
user avatar
  • 20.7k
1 vote
Accepted

Questions regarding pset4 Blur filter (less comfortable)

Because BYTE can only values up to 255. If say all three RGB values were already 255, then the sum would overflow the variable. If both dividend and divisor are ints in a division, then it's integer ...
user avatar
1 vote
Accepted

My CS50 PSET4 Filter (Less) Blur function doesn't pass check50 despite seemingly working fine

"The code seemingly blurs images without error" indicates a problem. "Seemingly" correct output is not exactly correct. It tells me that the actual digital data output needs to ...
user avatar
  • 63.4k
1 vote
Accepted

Mario (less) PSET6 Python Spacing help

When translating your original code from C to Python, you copied the indentation. That third for loop is not nested inside the second. In C, this doesn't matter because it ignores indentation and will ...
user avatar
1 vote
Accepted

Can someone help me understand what I am manipulating in the for statement?

Hmmm, it's funny, but most people have no trouble printing the #'s and fight with printing the spaces. You've almost figured out the spaces, but are having trouble printing out the hashes. Save your ...
user avatar
  • 63.4k
1 vote

pset1 cash less, problem using for loops

Normal practice is to use a for loop when the number of passes is well defined, either by a hard coded value or by a value contained in a variable. When the number of passes is based on a condition or ...
user avatar
  • 63.4k
1 vote
Accepted

pset1 cash less, problem using for loops

You need a semicolon immediately after each for loop. Otherwise, all the statements until the next semicolon are considered the body of that for loop. The compiler will complain if you put a semicolon ...
user avatar
  • 165
1 vote
Accepted

PSET 1 Can't implement loop at the prompt

Do you know how you would confirm that the variable was stored? i.e. in response to the question "confirming (for yourself) that you’ve indeed stored the user’s input successfully?" $ ./...
user avatar
  • 28
1 vote

Unable to compile pset1. Mario (Less comfortable)

I fixed it for you. #include <cs50.h> int main(void) { //Prompt for the height of the pyramid int height; do { //Takes input, assigns it to height and prints it ...
user avatar
  • 450
1 vote
Accepted

pset4 problem with blur, can't find what's wrong

You are averaging the values in the wrong place. You have to calculate the average after you have added all the values around the current pixel. Don't forget to reset the variables for the following ...
user avatar
  • 1,561
1 vote
Accepted

Unexpected results on resize(less). I could not figure out how is not working the way it suppose to be. Please help

For rewinding the input file, you forgot the - in front of (bi.biWidth * 3 + padding). With a positive number and SEEK_CUR, you skip forward.
user avatar
  • 20.7k
1 vote
Accepted

PSet 3 resize (less)

I'll give you several nudges. Most of the problems arise from the nested for loop structure being off. For example, the current code writes out padding after writing out every pixel. It should only ...
user avatar
  • 63.4k
1 vote
Accepted

PSET3 - Resize (Less) : Random colours being printed?

Did you notice that the first line is ok and everything after that is bad? Remember that there's padding at the end of each line in the input file. The code needs to skip over that padding before ...
user avatar
  • 63.4k
1 vote
Accepted

pset3 Resize - Invalid or unsupported Image Format

Have you actually looked at the raw hex data contained in the program's output files? Notice anything interesting? Where is the bmp signature that's supposed to be in the first 2 bytes? Next ...
user avatar
  • 63.4k
1 vote

One fail for check50 on pset6 similarities --less

With your remove, you only remove the first occurrence of the element, and only from one list. Also, changing the iterable you are iterating is bad style, can lead to unexpected or sometimes even ...
user avatar
  • 20.7k
1 vote
Accepted

Why is my program not entering the while loop in greedy? Pset1

You've run into float imprecision, which is the lesson of this Problem. The spec and walkthrough advise you to convert the user's float amount into an integer representing the number of cents (and to ...
user avatar
  • 18.3k
1 vote
Accepted

Need help in pset1: mario.c

Think about the logic of printing hashes. First, forget about the spaces when printing hashes. Next, think about these questions: How many hashes are supposed to be on the first line of the pyramid? ...
user avatar
  • 63.4k
1 vote

resize less comfortable recopy - issues

First issue: The code has a logical infinite nested loop because the same control variable, o, is used in two loop setups. The result is that the outer loop never completes. Next, a programming tip. ...
user avatar
  • 63.4k
1 vote
Accepted

Final bfSize calculated does not match output file size

First of all, you shouldn't have to have an if statement to calculate the image size depending on whether there is padding or not. Next, think about this. biWidth is measured in pixels. Padding is ...
user avatar
  • 63.4k
1 vote
Accepted

can someone please tell me whats wrong with my code ? on clicking the compare button on my website , its showing me some error

You don't mention what the error is, but more than likely it's caused by you returning a list inside a list. If list(s) returns a list, then [list(s)] returns a list containing one list. You should ...
user avatar
  • 18.3k
1 vote

Pset4 (less) - vertical resizing

Oh my god those fixes did it. Actually thought about the width and height issue right after I posted this question. Thank you so much! This pset has been a real bear for me and I've been going back ...
user avatar
  • 21
1 vote
Accepted

tried to import windowed from more_itertools (for pset6 similarities less), but module not found

You might consider cloning your workspace in CS50 IDE > Dashboard. Then experiment in the clone to learn whether it will "break" your IDE. Since backup is hardly ever a bad idea, you can backup your ...
user avatar
1 vote
Accepted

Pset6 similarities (less) works but doesn't pass check50

return [] This returns an empty list. So all of your functions are returning empty. Be sure you return a list of the strings; don't print them.
user avatar
  • 18.3k

Only top scored, non community-wiki answers of a minimum length are eligible