Questions tagged [for-loop]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
5 views

Why does this change in my Tideman sort_pairs function cause it to work?

I was surprised to see that in my sort_pairs function for Week 3's problem Tideman, changing the boundaries of my two for-loops from pair_count to pair_count - 1 causes check50 to say that the pairs ...
user avatar
1 vote
2 answers
34 views

PSet1 - Coins issue

While doing the Coins problem set, I am receiving an error while trying to compile and I can't figure out what the issue is. "cash.c:53:27: error: variable 'cents' used in loop condition modified ...
user avatar
1 vote
2 answers
37 views

Stumped on PSET 1 Mario Less Comfortable

I've been working on this for a while and feel stuck. I think that my "for" loops might be out of order or some other issue. Suggestions? Thanks
user avatar
0 votes
2 answers
18 views

for- loop stop if output A

on pset2/caesar and only when ciphertext[i] = A or a for loop stopped ????
user avatar
0 votes
0 answers
27 views

How to get the index of iteration from the 'for' loop?

I've been trying to solve pset6 (DNA in specific). I finished all of its parts but stuck on the part of comparing two lists. A list of lists containing the STR repetitions of each person (sth like ...
user avatar
0 votes
1 answer
27 views

Isalpha not working for all char of my string

I'm trying to use the isalpha() function to check whether all characters of a string are letters or not. However, when I use the debug50 module, it looks like after the first character of the string, ...
user avatar
  • 3
0 votes
2 answers
223 views

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

I'm having a problem with an output. Sometimes output adds an extra characters, different each time the code runs. For example, when I use key "1" and write "a", it displays "...
user avatar
0 votes
1 answer
27 views

CS50 Final Project Jinja For Loop Not Running

My final project is a task website that allows you to create tasks, complete them, and get alerted when you haven't done a task on time. Currently, I am working on alerting when the task is due. The ...
user avatar
  • 67
0 votes
1 answer
50 views

PSET8 Web Finance - Index/Portfolio - Why do my for loop variables not pull over to Portfolio.html?

I have the below code for my application: #valid stock row queries valid_stocks_rows = db.execute("SELECT symbol, SUM(shares) as sum_total FROM ledger WHERE user_id=:user_id GROUP BY symbol ...
user avatar
1 vote
1 answer
24 views

Caesar pset2, printing out the cipher text

I know I'm doing this wrong, and it seems like something I should already know, but for the life of me I can't figure out what I'm doing wrong or how to fix it. Any help would be greatly appreciated. ...
user avatar
0 votes
2 answers
66 views

Finance - Index showing correct number of rows but all the same record. For- loop issue?

So I've been looking at this all morning and can't figure what I'm doing wrong. All my variables are producing the correct values so it seems to be something to do with my For loop. In the html ...
user avatar
  • 9
0 votes
1 answer
28 views

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

It's a simple Python program to find the number of primes until a certain number. The for z in range(1,y): loop does not execute, but rather execution jumps to the print(count," Pr...) statement ...
user avatar
  • 103
1 vote
1 answer
131 views

pset3 Plurality

Having an issure writing my plurality code pset. i wanted to have my programme promt a user when they have made an invalid vote entry. and it works ok but ive found a bug while testing it: code: #...
user avatar
0 votes
1 answer
24 views

My program doesn't run when i close the condition's range. When i leave the range open it does't give the answer i want

#include <cs50.h> #include <stdio.h> #include <math.h> int main(void) { float change; int cents = 0, coin_number = 0, quart = 25, dime = 10, nickel = 5, penny = 1; //...
user avatar
0 votes
1 answer
40 views

Hexadecimal to Decimal Conversion - Loop runs in reverse order (opposite to what is expected)!

The following code converts Hexadecimal numbers to Decimal numbers (successfully). I'm unable to figure out why the code behaves in just the opposite manner as it should be! I was planning to write: ...
user avatar
  • 3
0 votes
2 answers
201 views

what is the significance of break; in tabulate function?

I know break statements are pretty basic, but it's got me here: This is my function: for (int i = 0; i < voter_count; i++) { for (int j = 0; j < candidate_count; j++) { if (...
user avatar
0 votes
1 answer
1k views

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

I'm working on the Credit problem set. Along the way, I've encountered a scenario where I want to use a for loop to store multiple values. If I type printf("%d", cc_number[p]); in that for loop, it ...
user avatar
0 votes
1 answer
14 views

Pset 2 - loop question

im trying to make it so my program returns Success after it checks whether the provided argument is all digits. i can see why this code prints success 3 times if i provide a 3 digit number as the ...
user avatar
  • 5
0 votes
2 answers
81 views

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

I am having an issue specifically with the second for loop (under "//iterate over key inputs" comment). The counter j is going over the strlen of argv[1], and thus feeding a wrong input to my shift ...
user avatar
0 votes
1 answer
24 views

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 [closed]

#include<stdio.h> #include<string.h> unsigned int FindFunctionDefn( char strFunctionName[], char strSourceCode[] ){ int n = strlen(strSourceCode); int m = strlen(...
user avatar
0 votes
1 answer
40 views

mario and problems with my array

# include <stdio.h> #include <cs50.h> So I've been playing around with this problem alot and unforturnatly asked many questions. But I think I've figured out the basics, if not back to ...
user avatar
0 votes
2 answers
211 views

pset4 how does incrementing j help to iterate over pixels?

I'm currently working my way through understanding the code of copy.c used in "whodunit" and "resize". This loop is supposed to iterate over the scanlines of a Bitmap (by incrementing i) and within ...
user avatar
0 votes
1 answer
93 views

Many Error Messages Surrounding For Loop

I've been working on my caesar.c and I've built this so far. Unfortunately when I try to compile it I'm greeted with a flood of error messages surrounding the for loop noted below. I cannot figure out ...
user avatar
  • 3
1 vote
1 answer
47 views

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

This is my first question on Stack Exchange. I had a few different issues with this problem but I felt I'd finally sorted them out until I ran into this. I've been working for a number of hours today ...
user avatar
0 votes
1 answer
34 views

PSET3 Game of Fifteen init for loop stops unexpected

So I am stuck at initializing the board. my for loop is doing what it should but it stops when it is not actually done. The board I initialize is made of the dimensions d * d and should start left to ...
user avatar
0 votes
0 answers
38 views

What is wrong with my code?

In this program I am trying to receive an input as a string using argv[] and then I am trying store corresponding values of argv[1][i] into an array var[i] using switch case and I am finally adding up ...
user avatar
0 votes
1 answer
28 views

I have described below the problem. Can someone answer? [closed]

For(i=4; i<8 ) so in the start with i = 4 and I want to get 4+1=5 5+8=13 13/2=6 6+1=7 7+8=15 15/2=7 7+1=8 0,1,2,3,4,5,6,7,8 How do I do this?
user avatar
0 votes
1 answer
43 views

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

everyone! I really need your help. I'm working on pset4 and trying to understand the logic of resize problem. I have two files:testinp.txt and testout.txt. Inside of testinp.txt I have: ...
user avatar
0 votes
1 answer
772 views

Problem with "expression result unused error" in for-loop?

I am getting an error message of "expression result unused" for the bottom two for loops (specifically h + 1 and s - 1). I've tried looking for through the other questions for an answer but nothing ...
user avatar
  • 1
0 votes
1 answer
984 views

For loop help in python

i'm trying to do a 'for' loop in python, but my values keeps getting replaced. How can i write the code below in a way where i can keep a record of each iteration? Should i be using a list[] instead ...
user avatar
  • 179
1 vote
1 answer
5k views

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

I felt like I could understand the for loops great in c, but seem to be hitting a wall here. Some generic conceptual questions before i get into it: 1) ANSWERED. what sequence does the program run, ...
user avatar
  • 179
0 votes
1 answer
301 views

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

I'm porting crack.c to crack.py. I crack.c, I am able to do this: for (int i = 0; i < sizeof(letters) && strcmp(hash, solve) != 0; i++) In order to break the for() loop if I find the ...
user avatar
0 votes
1 answer
216 views

new to Python: for loop

I see David using a lot of for loops like this, usually in a table: for (singular variable) in (plural variable) e.g. for registrant in registrants He doesn't actually declare the singular ...
user avatar
  • 179
1 vote
1 answer
106 views

PSet1 While Loop to Print Spaces for Mario Not Working

I have approached this problem by using a forloop with two nested loops. The second nested loop works and prints the correct number of hashes. The first nested loops does not appear to working at all, ...
user avatar
3 votes
3 answers
12k views

MARIO LESS COMFORTABLE

I have been working at this pset for hours. within 5 minutes i got the hello.c and water.c assignments completed. But when it comes to mario.c, I am utterly lost. I have watched every video. I ...
user avatar
0 votes
0 answers
521 views

I'm working on isbn.c. Here, instead of one 'yes', it's displaying several yes'es. What mistake did I make?

Why is my output showing 'yes' multiple times? I think it's because the values of 'num' and 'num1' are being run separately each time to make the value 'finally', but I'm not sure. Please help me fix ...
user avatar
0 votes
2 answers
62 views

PS7: Please give me a hint on flask loop usage

Despite reading documentation I cannot figure out why my loop is not functioning properly and is only dynamic for stock symbol? Am I meant to be using multiple nested loops passing all prices, holding ...
user avatar
  • 5
0 votes
1 answer
1k views

CS50 2017 Problem Set 6 Mario.py For loop

What is wrong with my second For Loop (spaces)? It seems like it only runs one time, according to the first line of the pyramid. import cs50 while True: print("Type a number between 0 and 23: ", ...
user avatar
0 votes
1 answer
87 views

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

Here is my code: include include int main(void) { int h; //gettin some input. do { h = get_int(); printf("height:\n"); //prompting for input. } while (h <= 0 || h > 23); //...
user avatar
0 votes
1 answer
418 views

Loop breaking in quick sort algorithm

Implement quick sort algorithm with faulty results. Details of what I want to do can be found at the video: https://courses.edx.org/courses/course-v1:HarvardX+CS50+X/courseware/...
user avatar
0 votes
1 answer
86 views

Parentheses or Brackets Problem?

I get this error, but I can't find where I forgot a paren / bracket... int SUM1 = 0; if ( (length == 13) || (length == 15) ) { for (int a = 1; a < length; a++2) { ...
user avatar
0 votes
1 answer
69 views

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

I watched the walkthrough for load, but I am struggling to understand what the problem set is asking for. What is load's objective, and what is the best way to approach load? I also don't know ...
user avatar
0 votes
1 answer
68 views

vigenere.c cs50 plaintext for loop starts after the key array loop ends

i need help in the sense that if i run my program with the key being one letter, whether capital or lowercase, it works properly, but if more than one letters in the key, the last letter is used for ...
user avatar
0 votes
1 answer
26 views

FOR loop error when compiled

Hey guys i was getting some compile errors on for loops that I thought to be sound, i put together a simple test for loop and received the same errors. Have i made a mistake or is there something ...
user avatar
0 votes
1 answer
285 views

Hacker pset1 credit.c always gives invalid?

I tried to attempt the credit.c problem. My code is as follows: #include <stdio.h> #include <cs50.h> #include <math.h> #include <string.h> int main(void) { printf("Please ...
user avatar
1 vote
1 answer
535 views

still needing help with mario

I have read and re-read through the help provided for mario here and other places, but am stuck at getting the right number of lines, but not the right characters in each line (i am substituting a for ...
user avatar
0 votes
1 answer
191 views

For Loops in Itsa Mario pset1

I don't understand what to put in for the (initialization; condition; update) part of the for loop. I used 4 variables in my code: i = height, r = rows, j = spaces, n = hashes. Whenever I type in "...
user avatar
0 votes
1 answer
71 views

Pset1 Greedy: How can i use a variable that is inside a for loop, outside the for loop?

//My code prints all of the coins //I cannot seem to be able to use the variables that are inside the for loop, outside that loop. //Any Ideas? int main(void) { float f; do { ...
user avatar
0 votes
1 answer
17 views

New at programming....Code output different than expected. Any ideas why?

I am working with flags and have the following code. The output I should receive is below the code; however, when I compile, the output is different. Can someone explain why this is? Thanks. int ...
user avatar
0 votes
1 answer
1k views

C prog - COUNTER to find the number of alphanumeric's character in a string?

I'm trying to write a function to count the number of alphanumeric character(a,b,c,d,..,z), in a string. My code looks like it doesn't have error..., but when I run it, function stops to count ...
user avatar