Questions tagged [loop]
The loop tag has no usage guidance.
50
questions
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 ...
0
votes
1
answer
20
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
1
answer
6
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 ]
0
votes
2
answers
61
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 ...
1
vote
0
answers
362
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, ...
0
votes
1
answer
91
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 ...
0
votes
2
answers
62
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 ...
0
votes
1
answer
58
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];
...
0
votes
2
answers
213
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 (...
1
vote
1
answer
277
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 ...
0
votes
1
answer
454
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
1
answer
38
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>
#...
1
vote
1
answer
219
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))
{
...
2
votes
1
answer
272
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'...
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 ...
0
votes
1
answer
148
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
1
answer
178
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
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 ...
0
votes
1
answer
158
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
1
answer
125
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
1
answer
119
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
2
answers
37
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 ...
1
vote
2
answers
209
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
2
answers
96
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
2
answers
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-...
0
votes
3
answers
762
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
1
answer
71
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
1
answer
374
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. ...
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 ...
1
vote
1
answer
232
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
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 ...
0
votes
1
answer
60
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
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 = (...
0
votes
1
answer
242
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
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 ...
0
votes
1
answer
94
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
1
answer
117
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
1
answer
493
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
1
answer
266
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
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 ...
0
votes
1
answer
694
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
1
answer
967
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
1
answer
296
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 ...
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.
...
1
vote
2
answers
125
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
1
answer
262
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 ...
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>...
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 ...
2
votes
2
answers
237
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?
2
votes
2
answers
2k
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 ...