Questions tagged [do-while]

The tag has no usage guidance.

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

do a+b while its not divisible by c

I am completely new to C and also programming, and I have to make algorithm for: a=2 , b=3 and add "b" to "a" and display results of it until its divisible by 7 I tried something like this but I cant ...
0
votes
2answers
101 views

Problems on mario (pset1)

I want to test how the do-while loop works. But I encounter a problem, which I've spent an hour working on but couldn't figure out a solution. Here's my code. int main(void) { int n; do { ...
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
1answer
142 views

Pset1 Water Issue, reprompting with “Retry: ” for Non-integers, and “Minutes: ” for negative integers

My water program seems to work decently, it passes all of the check50 tests just fine. My issue is that when the user enters a negative integer, the program re-prompts with "Minutes; ", but when the ...
0
votes
1answer
2k views

Mario Less Comfortable, do-while loop problem

Hi everyone I made sure to do my research and go through the already posted questions. I am certain my while condition is wrong after research but don't understand the correction. my program runs but ...
0
votes
1answer
76 views

Greedy - Do While Negative Float

I'm testing the very first requirement of the Greedy assignment (ensure the input is not negative). I'm running into an issue where if I use < 0 in the while statement, -0.1, -0.2, -0.3 etc. is ...
0
votes
1answer
75 views

pset1 water how to ignore negative number

On the screenshot is the result after I typed a negative integer. How do I ignore the negative integers on bottles' result? Help pls. The positive & zero results are just fine, but the negatives ...
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
53 views

PSET1 mario.c why if and return

I was banging my head with this. I had to look at others solutions to get my code to work. Here is the code I have, it works now but only because I looked at solution. I had this code written minus ...
0
votes
2answers
372 views

Do-while loop in pset1 returning negatives

I can't get the do-while loop in water to work. It will take a positive number and then return the right thing and quit the program, but if given a negative number it spits out a negative water amount ...
0
votes
1answer
135 views

Codestyling and whitespaces are important in Python? PSET6 [duplicate]

codestyling and whitespaces are important in Python? I have this simple code and works... import cs50 while True: print ("Type a number between 0 and 23: ", end="") n = cs50.get_int() ...
0
votes
1answer
597 views

Can't get the do-while loop to work in pset1

I have been trying to follow the walk through for pset1 and I cannot get my code to work for the first part of water. It will not let me execute the do-while loop. I have written the code just like ...
0
votes
1answer
104 views

PSET 4 recover.c - segmentation fault, do while loop

I have almost written working a recover.c. But when I want to use do while loop, memory segmentation fault appears. Of course I can write a code in a different way avoiding do while loop, but I want ...
0
votes
1answer
33 views

Do While loop not executing for pset3

I am working on Pset3 for a binary search algorithm. Below is my code (NOTE: the logic is not finished): bool search(int value, int values[], int n) { //binary search algorithm int min = 0; int max = ...
0
votes
1answer
201 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
3answers
169 views

PSET 1 Mario Code Problem

Would someone be as kind as to tell me what I got wrong for this section of my code? Thanks so much in advance!
0
votes
2answers
580 views

pset1 "expected identifier error in do-while loop

I have been struggling with this for weeks now, have done several searches and posts and can not seem to get around this. I have tried everything and it just makes it worse. I wish there was a video ...