Questions tagged [for-loop]

The tag has no usage guidance.

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

How to make pset 3 runoff effect multiple eliminated candidates?

#include <cs50.h> #include <stdio.h> #include <string.h> // Max voters and candidates #define MAX_VOTERS 100 #define MAX_CANDIDATES 9 // preferences[i][j] is jth preference for ...
Harr's user avatar
  • 35
1 vote
1 answer
14 views

Nested for loop not returning to parent in substitution.c

I have a nested for loop of for(int i = 0; i < strlen(key); i++) { for(int j = i + 1; j < strlen(key); i++) { if(toupper(key[i]) == toupper(key[j])) { ...
user21380365's user avatar
0 votes
1 answer
30 views

How to Add results of a for loop

any ideas on how I could add the results of a for loop in C? I'm currently working my way through lecture 1, so I only know a few skills in C so far. My for loop does what I need it to do - it outputs ...
Joseph J Filoramo's user avatar
0 votes
1 answer
11 views

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

So, I'm currently working on 'Substitution', and have written the following code to evaluate if a certain array of characters are all alphabetic: for (int i = 0; i < length; i++) { if (isalpha(...
mstack's user avatar
  • 3
1 vote
2 answers
64 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 ...
Calvin Lee's user avatar
1 vote
2 answers
241 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
Patsy Lin's user avatar
0 votes
2 answers
19 views

for- loop stop if output A

on pset2/caesar and only when ciphertext[i] = A or a for loop stopped ????
Mohamed Al-sarf's user avatar
0 votes
1 answer
86 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, ...
jamba's user avatar
  • 3
0 votes
2 answers
882 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 "...
D3sl0nG3r's user avatar
0 votes
1 answer
37 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 ...
mkg15's user avatar
  • 67
0 votes
1 answer
51 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 ...
allemandi's user avatar
1 vote
1 answer
52 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. ...
Tanya Pleau's user avatar
0 votes
2 answers
91 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 ...
GFitzP's user avatar
  • 19
0 votes
1 answer
136 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 ...
An Ant's user avatar
  • 103
1 vote
1 answer
193 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: #...
Pot Noodle's user avatar
0 votes
1 answer
25 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; //...
Gloria Isedu's user avatar
0 votes
1 answer
57 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: ...
Ishan's user avatar
  • 3
0 votes
1 answer
238 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 (...
Musical_Ant's user avatar
0 votes
1 answer
2k 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 ...
Trifonas-Kaoulla's 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 ...
owwix's user avatar
  • 5
0 votes
2 answers
84 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 ...
Amanda Ramirez's user avatar
0 votes
1 answer
25 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(...
manish_rocks's user avatar
0 votes
1 answer
50 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 ...
MikaLand's user avatar
0 votes
2 answers
228 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 ...
Sigmund's user avatar
0 votes
1 answer
99 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 ...
D. B's user avatar
  • 3
1 vote
1 answer
48 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 ...
CaveThing's 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 ...
user8098068's user avatar
0 votes
0 answers
40 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 ...
Aashish Loknath Panigrahi's 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?
Tom55555's 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: ...
Paius Usoroh Akpan's user avatar
0 votes
1 answer
804 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 ...
Micky's user avatar
  • 1
0 votes
1 answer
1k 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 ...
nvs0000's 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, ...
nvs0000's user avatar
  • 179
0 votes
1 answer
304 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 ...
burningserenity's user avatar
0 votes
1 answer
253 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 ...
nvs0000's user avatar
  • 179
1 vote
1 answer
109 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, ...
Alex Durante's 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 ...
Austin Tyler Cunningham's user avatar
0 votes
0 answers
550 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 ...
ASharma's user avatar
0 votes
2 answers
63 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 ...
idol2k's 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
90 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); //...
Jeremy Francis Webb's user avatar
0 votes
1 answer
448 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/...
Marcello Scattolini's user avatar
0 votes
1 answer
101 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) { ...
KhalidMukadam's 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 ...
SuperNovaCoder's user avatar
0 votes
1 answer
70 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 ...
Ubuntu NutCracker's user avatar
0 votes
1 answer
29 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 ...
Bradley Jonathan Guinen's user avatar
0 votes
1 answer
295 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 ...
user107224's user avatar
1 vote
1 answer
541 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 ...
user11386's user avatar
0 votes
1 answer
198 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 "...
BB8-2597's user avatar
0 votes
1 answer
74 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 { ...
Maria Nunez's user avatar