What we want is that the user input, with the get_int function is inside the DO-WHILE loop, we do not want to print the number of bottles inside that loop because if i is positive the end condition of loop (i> 0) does not Is never fulfilled, and we have an infinite loop. The solution is to ask the user a positive number, that is to say we keep asking for a ...
OK, you are pretty close, just some little syntax errors.
When I try to compile your source code with clang I get the following errors, so let's solve them step by step:
test.c:11:26: error: expected ';' at end of declaration
int i = get_int()
You get that error because you forgot to insert a ; ...
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 ...
Remove the = get_int() in line 7.
Take the = (minutes * 12) from line 8, and move it as bottles = minutes * 12; (then without the int as you already declared it) somewhere below the remaining = get_int(), either in or below the do..while loop, but before the final printf.
What I might do is put the first printf before the loop, and then the second printf as an additional prompt that gets repeated as needed.
print "How many minutes? "
print "Please enter a positive number: "
get the int
while (it's negative)
So the first time it runs, the user sees:
"How many minutes? Please enter a positive number: ...
Like @Mars said, nothing is wrong with your program. The :) in check50 means that you did something right! An error in check50 is shown by a :(. For example, if your program didn't work, you'd get something like :( rejects "123abc" minutes followed by a line showing what the expected output was and what the actual output was.
If you still have issues, ...
Try taking away the semicolon after int main (void). From there you will have to go through and fix your other errors, but those should be easier to fix. Just run make and then go through each error one by one. I hope this helps!
If this answers your question, please click the check to accept:)
in 2017 the GetInt() function is depreciated
water.c:8:9: warning: 'GetInt' is deprecated [-Wdeprecated-declarations]
It works for:-
otherwise user is prompted to "retry".
note: view the Walkthrough video.
is a format specifier wrong for an integer, the right thing would be %i, or %d. Since NumberOfBottles is an integer, the variable is unused, hence the second error, but in this case will be corrected when we use the correct formatting for an integer.
The most obvious things are we overlook, excuse my cluelessness.
The error persists because we ...