Skip to main content

Questions tagged [loop]

The tag has no usage guidance.

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

CS50x: Issue on problem Felipe´s Taqueria, program keeps asking me for input, without printing price, why?

I am trying to execute the problem "Felipe´s Taqueria", but I am failing to see any price printed as output. Instead the program keeps asking for input. When I input "Taco", the ...
Elvino Michel's user avatar
1 vote
2 answers
143 views

variable used in loop condition not modifies in loop body

im struggling with pset1 cash exercise, when im defining a calculate_quarters() and other in the same way i got an error. the task is to find out the number of quarters, dimes, nickels and pennies to ...
liza's user avatar
  • 13
0 votes
1 answer
8 views

where am i making mistake here? problem set2 substitution

hey here i am trying to return 0 if argument string contains all 26 alphabet characters otherwise function should return 1 and print message]1 ]
Abhi's user avatar
  • 1
1 vote
0 answers
1k views

pset2 - Bulbs - reversing array turns out wrong

I managed to make the right sequence of binary code (in reverse). Next, I do a for loop for reversing it, but it prints out wrong. I have no idea what happens, as the original array is correct, ...
yogmel's user avatar
  • 11
0 votes
1 answer
138 views

Choice of loops in C: Are the three loops exclusive or replaceable for a task

#include <stdio.h> #include <cs50.h> int main(void) { int h; do{ h=get_int("h"); } while(h<0||h>8); } In the above example, there is a reason to opt for do-while loop ...
Splendid Digital Solutions's user avatar
0 votes
1 answer
30 views

help with python loops

I am trying to make a program for myself, not really related to any particular problem set. The issue I am having is that I want a loop to iterate over a block of code and force the user to give one ...
Multiplify's user avatar
0 votes
2 answers
79 views

Why does this become an infinite loop?

I am trying to make a pyramid of hashtags somehow which I haven´t figured out yet, and trying my way step by step. (I´m doing the Cs50 course) When I came this far the program is working wohoo so far ...
l_b's user avatar
  • 7
0 votes
1 answer
61 views

Check function pset5 speller

I've been stuck on this for hours, please help. bool check(const char *word) { char check_buffer[LENGTH + 1]; for(int i = 0; i < strlen(word); i++) { check_buffer[i] = word[i]; ...
bobthebuilder's user avatar
0 votes
2 answers
241 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 (...
Angel's user avatar
  • 3
0 votes
1 answer
24 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 ...
Wh0am3ye's user avatar
0 votes
1 answer
64 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 ...
DZV31's user avatar
  • 1
0 votes
1 answer
533 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 ...
sclemson's user avatar
0 votes
1 answer
42 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> #...
mpetras's user avatar
1 vote
1 answer
229 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)) { ...
Entonis's user avatar
  • 11
0 votes
1 answer
149 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 ...
Jake 's user avatar
  • 37
0 votes
1 answer
198 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. ...
Jon's user avatar
  • 3
0 votes
2 answers
98 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 ...
SBT Learner's user avatar
0 votes
1 answer
161 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: #...
mschweitzer1's user avatar
0 votes
1 answer
126 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 ...
Dominikus Dermann's user avatar
0 votes
1 answer
120 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, ...
hpati1117's user avatar
0 votes
1 answer
217 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 ...
ahl89's user avatar
  • 3
1 vote
1 answer
279 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 ...
Tim's user avatar
  • 11
1 vote
2 answers
212 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 ...
Jason_V's user avatar
  • 182
0 votes
2 answers
61 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 ...
Nitish Panda's user avatar
0 votes
2 answers
97 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 ...
mlh's user avatar
  • 3
0 votes
1 answer
85 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 ...
Allison Hicks's user avatar
1 vote
1 answer
233 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 ...
Callum Gander's user avatar
0 votes
1 answer
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 ...
Amine Marzouki's user avatar
0 votes
1 answer
61 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 ...
Léon Othenin-Girard's user avatar
0 votes
1 answer
191 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 = (...
Jackson Lenhart's user avatar
0 votes
1 answer
244 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. ...
JLDG's user avatar
  • 7
0 votes
1 answer
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 ...
jwang1191's user avatar
0 votes
1 answer
95 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 ...
jwang1191's user avatar
0 votes
3 answers
764 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, ...
Tomas Vrba's user avatar
1 vote
1 answer
78 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 ...
Chris's user avatar
  • 159
0 votes
1 answer
120 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, ...
Mark Katzenberger's user avatar
0 votes
1 answer
537 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.
RicochetRiot's user avatar
0 votes
1 answer
274 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 ...
Nathan Juan's user avatar
0 votes
1 answer
117 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 ...
Max Winston's user avatar
0 votes
1 answer
867 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 ...
Brian Poindexter's user avatar
0 votes
1 answer
1k 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--)
BooFluff's user avatar
0 votes
1 answer
308 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 ...
VAPORAS's user avatar
2 votes
1 answer
273 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'...
Alex Zamai's user avatar
1 vote
2 answers
129 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 ...
Brian T's user avatar
  • 53
0 votes
1 answer
376 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. ...
PhoenixSouffle's user avatar
3 votes
2 answers
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>...
Elliot Byford's user avatar
0 votes
1 answer
270 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 ...
user1475's user avatar
0 votes
1 answer
75 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 ...
Daniel Fishman's user avatar
2 votes
2 answers
3k 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 ...
Amal Javed Abdullah's user avatar
1 vote
2 answers
131 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. ...
Guy Bennett-Jones's user avatar