Skip to main content
3 votes
Accepted

Pset7, Index: How to use loops in Python and Jinja?

The for loop is working and is displaying exactly the data it has. And it technically (theoretically?) is identical to a for loop in C. Perform this code x times. Syntactically, you (normally) tell C ...
DinoCoderSaurus's user avatar
2 votes

MARIO LESS COMFORTABLE

Using the 5 pyramid as a guide: Height: 5          ##        ###      ####  &...
DinoCoderSaurus's user avatar
2 votes
Accepted

PSET6 Load - How To Approach? Also, Is It Better To Use While() Loop or For() Loop?

Q1. Should I use fgetc() or fread() A1.: You can make both work! Choose the one you're more comfortable with. Q2. I don't know whether to use a for loop or a while loop. Is one better for this ...
Yuri Laguardia's user avatar
2 votes
Accepted

FOR loop error when compiled

A small error. The second int in your for statement is redundant and the compiler doesn't like it. The first one will apply to both i and j. Remove the second int and you should be ok. If this ...
Cliff B's user avatar
  • 69.2k
2 votes
Accepted

Caesar : Extra random characters at the end of a char ciphertext array

You have to understand how printf and strlen work. Both of them (and several other functions) depend on the existence of the end of string marker, \0 at the end of the target string. If the EOS marker ...
Cliff B's user avatar
  • 69.2k
2 votes
Accepted

PSET2 Vigenere: Output bug, keyword loop going over strlen of key

There are a number of problems with this code. Let's deal with your question first. The code is constructed as a nested pair of loops. The outer for loop will loop over the length of the plain text ...
Cliff B's user avatar
  • 69.2k
2 votes

i want the number of line in which the function is locate , like the function "func2" is in second line so the output shoud be 2

The CS50 StackExchange is for questions about the CS50 course (and problem sets, etc.). It is not a general "I need help with my homework from another course."-forum. I'd suggest that if this is not ...
curiouskiwi's user avatar
  • 18.7k
2 votes

Stumped on PSET 1 Mario Less Comfortable

Looks like you have an extra for loop there, which will cause the entire thing to loop l times when that's probably not what you intended.
Fuelled_By_Coffee's user avatar
1 vote
Accepted

Isalpha not working for all char of my string

There are a couple issues here. First, there's a known issue with debug50. For certain library functions, if you "step into" the line of code with the function call, debug50 will try to step ...
Cliff B's user avatar
  • 69.2k
1 vote
Accepted

Running an 'if' statement inside of a 'for' loop; Need to continue loop w/o printing anything, but not sure what value to return

First, since not all the relevant code is here, we have to make some assumptions. First, length = strlen(key). Second, this is in main and not in a function that's called by main. Third, the code ...
Cliff B's user avatar
  • 69.2k
1 vote

PSet1 - Coins issue

You also have the problem that it will always produce 0 as a result because of this: return 0; Instead, it should return quarter; That still leaves the problem of leaving the correct amount of ...
Cliff B's user avatar
  • 69.2k
1 vote

PSet1 - Coins issue

There's a semi-colon after your for loop, so it's simply ignoring the body. Remove that and you should be good. You can do this without a loop. Think about how you would approach this if you were to ...
Fuelled_By_Coffee's user avatar
1 vote

Stumped on PSET 1 Mario Less Comfortable

in your code check the first for loop, why is the counter decreasing ? why do you need 4 for loops? to create the right aligned pyramid you need only 3 for loops. external loop, to count from the ...
Alvaro Barboza's user avatar
1 vote
Accepted

pset4 how does incrementing j help to iterate over pixels?

Both the i and j counters are used to count passes through the loops. They aren't actually used inside the loops, but they don't need to be. Let's start with the inner loop. biWidth is the number of ...
Cliff B's user avatar
  • 69.2k
1 vote
Accepted

Pset2 - Vigenere - Encypts all variations of "barfoo" as "ca\..." (no case issues)

The problem lies in the last for loop. The for loop is controlled by strlen(pt), which is recalculated on every loop iteration. Inside the loop, the ASCII values of the letters in pt are converted to ...
Cliff B's user avatar
  • 69.2k
1 vote

PSET3 Game of Fifteen init for loop stops unexpected

Your Code seem fine I just executed it and it runs okay. Update and restart your IDE and see if that solve your problem.
Chuma Umenze's user avatar
1 vote
Accepted

pset4 resize - can't write all the characters from infile to outfile

There is "\n" (new line) char in the end of the first raw. So there are 33 chars, while you read-write only 32.
obesman's user avatar
  • 1,139
1 vote
Accepted

For loop help in python

In a dictionary the indices use strings, whereas lists are indexed using integers beginning with 0. The error: TypeError: list indices must be integers, not dict is because you are using string as ...
Ryan McCauley's user avatar
1 vote
Accepted

CS50 Final Project Jinja For Loop Not Running

It's running but nothing "matches" (ie is true) because of the date formats. Assuming "due_date" is TEXT in the db with the format "YYYY-MM-DD", current_date needs to be ...
DinoCoderSaurus's user avatar
1 vote
Accepted

Python - for loop not being executed, leading to NameError of variables defined in the loop

If y is 1, the z loop doesn't run. From w3schools: The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified ...
DinoCoderSaurus's user avatar
1 vote
Accepted

pset3 Plurality

https://cs50.stackexchange.com/a/38819/25714 Check this post on seg fault (plurality) that I have answered. If found to help be sure to tick the answer to keep other smiling too 😃
Shehroz Ali's user avatar
1 vote
Accepted

what is the significance of break; in tabulate function?

Each round counts one vote per voter, for their top preferred, non-eliminated candidate. Once that vote is counted, program moves on to the next voter. From the C99 standard section 6.8.6.3: A ...
DinoCoderSaurus's user avatar
1 vote
Accepted

How To Use a For Loop To Store Values Into Multiple Variables?

Since you have identified in your code sample above that you understand how to declare and put values in an array. Then I suggest the simple means is to just create an array of 8 length that can store ...
Nicknapoli82's user avatar
1 vote
Accepted

Pset 2 - loop question

Maybe you're just overthinking it a little? ;-) Just move the printf(Success) statement below the for loop. If the test fails, it's going to exit through the return statement. Otherwise, the code ...
Cliff B's user avatar
  • 69.2k
1 vote

PSET2 Vigenere: Output bug, keyword loop going over strlen of key

I would recommend you to do this problem set in one for loop. You can just loop through the plaintext. Using nested loops will make the problem more complicates than you think. It's because you only ...
Jn Wu's user avatar
  • 55
1 vote

How do I add a condition to a for() loop in Python?

You could use while and somewhat emulate for, or do an if with a break inside your loop (which I would prefer).
Blauelf's user avatar
  • 21k
1 vote
Accepted

PSet1 While Loop to Print Spaces for Mario Not Working

For the first inner loop, use a while loop, not do..while, as you don't want any space printed in front on the last line. The difference between while and do..while is that the do..while runs at ...
Blauelf's user avatar
  • 21k
1 vote

PS7: Please give me a hint on flask loop usage

If I understand this correctly, you are seeing the list of stocks but symbol, share_count, price_current and holding all display the values from the first stock. I think this "Am I meant to be using ...
DinoCoderSaurus's user avatar
1 vote
Accepted

CS50 2017 Problem Set 6 Mario.py For loop

I don't think it's a good idea to name the loop variable spaces when that name is already taken; that's probably where it goes wrong. Also, why don't you multiply the spaces like you did with the ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

pset1 mario.c this works, but can I better optimise?

My solution is very similar to yours. The printf("%s", " "); could be changed to printf(" ");. You could (not sure if you should) combine the two for-loops for(int j = 0; j < h-i-1; j++) //...
Blauelf's user avatar
  • 21k

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