Hot answers tagged

2

There's nothing wrong with the function. You just never call it from main. If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)


2

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 ...


2

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 ; ...


1

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 behavior: Number: -1 Number: foo Retry 2 But if you change your do while to this: do { num = get_int("Number: "); } while num < 0; Then you will ...


1

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.


1

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. Something like print "How many minutes? " do 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: ...


1

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, ...


1

Firstly, it should be int main(void) instead of int int(void) in the first line. Secondly, i hope you are using cs50 library. I checked your code after adding these things it is working fine.


1

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:)


1

in 2017 the GetInt() function is depreciated water.c:8:9: warning: 'GetInt' is deprecated [-Wdeprecated-declarations] now use get_int(); It works for:- Positive Integer Negative Integer Zero otherwise user is prompted to "retry". note: view the Walkthrough video.


1

%f 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. EDIT: The most obvious things are we overlook, excuse my cluelessness. The error persists because we ...


Only top voted, non community-wiki answers of a minimum length are eligible