Questions tagged [loop]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
32 views

pset1 cash less, problem using for loops

I tried to use for loops to solve the cash (less) problem set, not sure if thats possible. Can this code be fixed or do I need to use while loops instead? the code compiles, but the output is either (...
0
votes
1answer
11 views

Final Project - if statement with regex not working?

Working on my final project and I'm stuck trying to edit user input. The below code should take the first string in a list and check if it's numeric. If it is, great, that's what I want, otherwise, I ...
0
votes
2answers
40 views

Why the if statements don't work when I put them into loops? Caesar PSET2

Help, please. The program works fine until I want to add the loops and when I do that the if statements inside it won't work and it will just ask for the key and will output the same text as the input ...
0
votes
0answers
93 views

solved pset6 BUT still wondering

while reading the CSV file in these lines : csv_file = open(sys.argv[1], "r") # reading the csv file into memoery csv_reader = csv.DictReader(csv_file) when i tried to make a copy of the csv_reader ...
0
votes
1answer
90 views

Checking a string to see if it's an integer

I'm currently working on Caesar and I'm trying to go through each step in turn to complete it. As the problem set requires, I've written code that runs from the command line. The code below ...
0
votes
1answer
16 views

Pset Cash CS 50 - need help

It compiles without any problems, but when I try to execute it, the Terminal crashes. Do I get in some infinite loops here? I would appreciate some help - thanks a lot! #include <cs50.h> #...
0
votes
0answers
23 views

skip many loops error

I want if found something skips 4 or 5 loops if a = 20 and found something a will be 35 but didn't work why for a in range(len(cont)): if cont[a:a + len(str[c])] == str[c]: temp += 1 ...
1
vote
1answer
190 views

Key looping in Vigenere

I've reached the final step of Vigenere, but I don't really understand how do I loop the key over plaintext. This is the shift function I've created: int shift(char c) { if(isalpha(c)) { ...
0
votes
1answer
114 views

pset4 recover single image

My recover program currently successfully returns a single image "001.jpg" which looks good when I open the file. It also returns a second image "002.jpg" which prompts an error for an Unsupported or ...
0
votes
1answer
95 views

Why is it that the OR (||) doesn't work while the AND (&&) works in my program?

When I typed while (c != 'Y' || c != 'n' || c !='y' || c != 'N'); , my program just loops over, and over, and over again, even if I don't fulfil the condition, AKA, if I enter values Y, y, N or n. ...
0
votes
2answers
95 views

PSet 1, Trying to add a loop to Water

Right now I'm just playing about and trying to add various things to Water, just to get a hang of them. It's probably to over-engineered to get a pass or anything, but oh well. I'm trying to add a ...
0
votes
1answer
146 views

PSET1 Credit infinite loop when checking length

I'm working on credit.c in pset1, and I've decided to implement a "get length" method that I'm testing. I think my logic is sound, but I'm getting an infinite loop when running the following code: #...
0
votes
1answer
119 views

Pset 4: Stuck in a loop again (all green pixels)

So, I've figured out how to change the file headers and all. Works beautifully. The large image is the right size. I couldn't be happier. However, the large bmp image is just filled with neon green ...
0
votes
1answer
104 views

PSET3 Binary Search Function Infinite Loop

When I try running find.c inputting: ./generate 1000 50 | ./find 127 it should return that the value (127) was found, however when I do it with my code, it seems to create an infinite loop. Also, ...
0
votes
1answer
194 views

Pset1 Greedy; problem with do-while loop

When I try to run my code, I get prompted for the change amount, as desired, but when I enter an amount, nothing else appears in the terminal and the program does not calculate the minimum number of ...
0
votes
1answer
233 views

Problem in the do..while loop in Mario.c

before you block my answer for duplicates, I've spent over a day on this small bug. I've searched reddit, youtube and the stack exchange forums and still can't get it to work. I'm hopeless at this ...
1
vote
2answers
194 views

Trying to Increment Characters in a String

I am trying to increments the chars in my string (ie string x = (aaaa) all the way through (zzzz)). Is there a specific way I can use a loop to do this? I'm sorry if my question is newbie, I'm new to ...
0
votes
2answers
23 views

Will the loop break in case the condition returns some value to the caller method in C?

If i write the following: for(int i=0; i<=1000; i++) { if(arr[1] == n){ return true; } } Will the loop break when the condition holds true and the return statement returns the value to the ...
0
votes
2answers
93 views

Pset 2 - Vigenere Checking Command Line Input

I am working on the Vigenere portion of the pset and appear to have it totally working, yet when I ran the checker I realized that I had not created a test for non-alphabet characters in the command ...
0
votes
1answer
80 views

PS1 greedy question regarding formatting of do/while conditions

I am a beginner and have worked through the greedy algorithm part of PS1 (prompt the user for the amount of change needed, round/convert it to cents, and determine how the change could be dispensed ...
1
vote
1answer
190 views

pset2 caesar, argv[1]

Ok I'm consistently encountering a peculiar issue that I can't get my head around. this loop should return an error if there is a character other than a digit. When I give a character other than a ...
0
votes
1answer
42 views

Second condition doesn't seems to work properly

I've just solved my mario.c pset1, everything seems to work, but when I enter a value over 23 like 50 or so, the code is still running and drawing the pyramid then re-prompt the height. I've tried to ...
0
votes
1answer
52 views

In Check50 I get a Segmentation Fault, and trying myself gives me an endless loop

So I've been working my way through PSet5, and I can't seem to find out why I have a segmentation fault here, or why I get an endless loop. It says the fault is on line 31, which I'll mark in the code ...
0
votes
1answer
182 views

Mario pyramid loop arithmetic question

So I've got the program up and running, I'm just trying to understand exactly why it is performing correctly. I'm confused on this: for (rows = 0; rows < height; rows++) { for (spaces = (...
0
votes
1answer
238 views

CS50 Pset 2 Vigenere. Loop for the key word

I'm stuck with this problem, as the looping for the keyword isn't working and I don't find why. I've check already one answer about this topic but I don't see yet what the issue with my code is. ...
0
votes
1answer
193 views

Pset2 vigenere how to combine key loop with message loop

I think I have a basic understanding of what I need to do to solve vigenere. However, I have trouble applying the key loop to the message loop. Specifically, I have a couple of questions. I created a ...
0
votes
1answer
89 views

Vigenere - how to apply local variable in key to secret message

I've been a bit stuck in trying to solve this problem involving changing the key from one letter to the next. I haven't gotten to wrap around the key yet. I think I know what the problem is but need ...
0
votes
3answers
748 views

Infinite looping in hacker 1 - water

My do-while loop successfully rejects negative numbers and 0, however, if I input text such as "foo" when prompted for the length of a shower in minutes, the program runs into an infinite loop, ...
1
vote
1answer
29 views

Understanding continue statement in while loop in (pset6)

so I am all finished with pset6; however, I am having a hard time understanding what is going on here: while (true) { reset(); if (connected()) { // ..... bunch of other code that ...
0
votes
1answer
112 views

Any looping in greedy.c for pset1 to calculate coins and change remaining?

For greedy.c in pset1 I used a do...while to validate user input. But I couldn't see how to loop thru 25, 10, 5, 1 for quarters, dimes, nickels, pennies. I did the exact same calculation 3 times, ...
0
votes
1answer
199 views

do while loop not looping

I am having a problem with my do while loop. do { //this thing } while (n < 0 && n > 23); when I run it every time I enter a number ether valid or invalid it ends my program.
0
votes
1answer
189 views

Comparing chars

I'm trying to write some code that will take input, loop through the characters in the input, and print "hi" for every "a" that shows up in the input. I'm getting errors trying to compare the looped ...
0
votes
1answer
110 views

Breakout.c: GLabel Looping

I have created a You Lose/You Win message after a player runs out of lives or hits all the bricks. However, the code I've used seems repetitive and that's always bad! I'm thinking I could put the ...
0
votes
1answer
266 views

Why is my do..while loop executing only once?

I have tried to use a do-while outer loop with a for inner loop to implement bubble sort, but it appears to be executing once through the for loop and then not satisfying the while condition. The ...
0
votes
1answer
753 views

int i = 0; i < n; i++ compared to n>0; n--

Every time a forever loop is made, the statement in the parentheses is (i = 0; i < n(or some variable); i++) Why doesn't this work? (n > 0; n--)
0
votes
1answer
173 views

my while loop is not working

i wrote the following code in orde to get familiar with the while loop However , instead of executing the loop when i give a number lower than 1 it does the exact opposite !it executes the loops ...
2
votes
1answer
256 views

This webpage has a redirect loop [pset7]

I'm struggling putting online CS50 finance site. When I try to access it from internet http://172.16.29.128/pset7/public/login.php I get This webpage has a redirect loop with ERR_TOO_MANY_REDIRECTS. I'...
1
vote
2answers
103 views

Mario counter and output problem

I think I have a problem with the syntax of my main loop that counts the number of lines to output. When I set the counter = 1, it prints the correct number of rows but starts at the top with only 1 ...
0
votes
1answer
365 views

Loops in greedy.c give unusual outputs

Not quite sure what the problem is here, but I think it has something to do with my loops. I've been setting up the code a little at a time, adding the sections for each type of coin one at a time. ...
3
votes
2answers
1k views

What's wrong with my do while loop syntax?

On pset1 I'm trying to make a do ... while loop to get the user's input for the pyramid height for Mario. I swear it should be simple... This is my source code for dowhile.c: #include <stdio.h>...
0
votes
1answer
218 views

Infinite loop in speller.c check function

I can't seem to break out of this infinite loop here is my pseudo code: malloc cursor malloc new_node for(length of word) { if(letter is uppercase) { make letter uppercase } } copy string ...
0
votes
1answer
69 views

For loop doesn't start

I'm trying to create a function which will evaluate whether or not the user's command line input is a letter. The function returns an integer, which should be zero if the string is all alphabet ...
2
votes
2answers
1k views

Do do/while loops only take one line?

Whenever I put in more than one line in the do/while loop, I get this error. mario.c:9:7: error: expected 'while' in do/while loop printf("Nope, again please,\n"); ^ mario.c:7:5: note: to match ...
1
vote
2answers
128 views

pset4 Lives Unintentional infinite loop

I'm implementing part 9 of 10 in pset 4 when I found a flaw in my code. First, pseudo-code: If ball is below the screen remove ball Refer to initBall function to create new ball which is centered. ...
0
votes
2answers
237 views

Vigenere pset2 code runs one extra loop when non-alpha entered

My vigenere code enciphers properly, but if a non-alpha (i.e. space or number) character is entered in the code to be ciphered, it loops through an extra time. It doesn't matter whether it is one non-...
2
votes
2answers
232 views

How to Convert Integers to Spaces/Hashes?

I am stuck at converting the integer input I get from the user into spaces/hashes. How to use this integer with my printf() function to print spaces/hashes?