2
votes
Accepted
Do While loop not executing for pset3
Right before bool sorted = false;, you have return true;. You give a return value before anything else happens, so your function does exactly that: it returns that value and stops executing any ...
1
vote
do a+b while its not divisible by c
My bet is that when you tried to run it, it just sat there, looking like it is doing nothing. Actually, this is an infinite loop. It's running the loop thousands to millions of times over, depending ...
1
vote
do a+b while its not divisible by c
You can check divisibility like this
div = result % 7;
And I think you need to use integer instead float
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int a, b, result;
...
1
vote
Problems on mario (pset1)
The message is clear, you must learn to interpret it as a programmer since it is almost impossible to write a program free of errors at the first attempt. If you look at the first time that the ...
1
vote
Accepted
Problems on mario (pset1)
By this you declared (but did not initialize) the variable:
int n;
The following is recognized as a comment but not an initialization because of "//":
// n = get_int("Please type in an integer ...
1
vote
Accepted
Pset1 Water Issue, reprompting with "Retry: " for Non-integers, and "Minutes: " for negative integers
what you are seeing is a side effect of how get_int works. If you have something like:
int num;
do
{
printf("Number: ");
num = get_int();
}
while (num < 0);
And run it, you will see this ...
1
vote
Accepted
Greedy - Do While Negative Float
Well, let's think about what's happening. The code is changeOwed = get_float(); which is supposed to get a float and store it in changeOwed. However, changeOwed is declared as an int, not a float, ...
1
vote
Pset1 Greedy; problem with do-while loop
Your while loop does not end up
EDIT:
(Thanks to SuperNovaCoder for your intervention)
The problem is that equality must be achieved ie the conditions must be >=
EDIT1:
while(cent_amount>=0)
...
1
vote
Accepted
PSET1 mario.c why if and return
This conditional just says that if a height of 0 is entered, which is a requirement of the spec, the program ends by returning 0. If you want to print a pyramid of height 0, you don't actually need to ...
1
vote
Accepted
Do-while loop in pset1 returning negatives
Your code is actually doing what you told it to, but you told it to print out the number of bottles before it exited the for-loop. A simple fix is to put the printf outside the for-loop.
If you still ...
1
vote
Can't get the do-while loop to work in pset1
You lack the main function, all console programs must have a main function:
int main(void)
{
some code
}
The error is surely because the compiler thinks that you are going to define or declare a ...
1
vote
Accepted
PSET 4 recover.c - segmentation fault, do while loop
Looks like your are trying to write fwrite(&buffer, sizeof(buffer), 1, dest); before dest is defined. How so? Let's assume the first read does not find a jpeg signature. What then? It enters the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
do-while × 17pset1 × 9
mario × 6
cs50x × 3
loop × 3
water × 3
c × 2
greedy × 2
getint × 2
dowhileloops × 2
pset4 × 1
pset3 × 1
recover × 1
pset6 × 1
python × 1
cs50-ide × 1
binary-search × 1
cs50x2017 × 1
compilation-error × 1
water.c × 1
syntax × 1
while × 1
algorithm × 1
do × 1
negative × 1