Happy to help. You're running into syntax errors, which you'll have a lot of as you're getting started. Always best to cure them in order because sometimes the early ones cause a lot of later ones.
I think the reason you're not finding the first one is that it's one of those deceptive ones where the problem isn't on the line where it's being signaled. ...
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 further code.
This loop will run exactly once every time. Look at your test. It has to be true for the loop to execute more than once, but that will never happen. What number can be less than zero AND greater than 23 AT THE SAME TIME? ;-)
If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)
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 on how long you let it run.
Want proof? Add two lines of code:
int count = 0; //creates and initializes a counter
You can check divisibility like this
div = result % 7;
And I think you need to use integer instead float
int a, b, result;
a = 2;
b = 3;
result = a + b;
while ((result % 7) != 0);
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 variable n is declared is not initialized, the solution is simple and your program should be like this:
int n = 0;
n = ...
By this you declared (but did not initialize) the variable:
The following is recognized as a comment but not an initialization because of "//":
// n = get_int("Please type in an integer here: ");
So you can simply delete "//" and after that the variable will be initialized:
n = get_int("Please type in an integer here: ");
what you are seeing is a side effect of how get_int works. If you have something like:
num = get_int();
while (num < 0);
And run it, you will see this behavior:
But if you change your do while to this:
num = get_int("Number: ");
while num < 0;
Then you will ...
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, so the number returned from get_float() is cast as an int.
In the process of casting a float as an int, the decimal or fractional part is truncated, not ...
Your while loop does not end up
(Thanks to SuperNovaCoder for your intervention)
The problem is that equality must be achieved ie the conditions must be >=
To allow the loop to finish
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 print anything!
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 have issues/questions, comment below.
You lack the main function, all console programs must have a main function:
The error is surely because the compiler thinks that you are going to define or declare a function, the do-while loop is the most appropriate for this case.
All statements must end in semicolons (;)
int minutes = get_int()
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 do/while loop, and tries to write to dest, which is undefined.
Make sure you are using the CS50x 2016 version of the specification, in which the jpeg signature ...