Hot answers tagged

2 votes
Accepted

pset1 water task, function code ignored

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. ;-)
user avatar
  • 64.2k
2 votes
Accepted

Pset1: Water- Infinite Loop

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 ...
user avatar
  • 5,172
2 votes
Accepted

Can't get past step 2 in water.c check50 2016.water water.c?

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: ...
user avatar
  • 7,326
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 ...
user avatar
  • 18.4k
1 vote
Accepted

pset1 water how to only prompt once?

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 = ...
user avatar
  • 20.7k
1 vote
Accepted

Is there a better way to know when the loop is repeating?

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 "...
user avatar
  • 18.4k
1 vote

Water homework week 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 ...
user avatar
1 vote

code is compiled but not working, please give me feedback

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.
user avatar
1 vote
Accepted

Can't figure out this problem with water.c = error: expected identifier or '('

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 ...
user avatar
1 vote

pset 1 water fails check50 "rejects "foo" minutes"

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 ...
user avatar
1 vote

My water.c program won't compile - Pset1

%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 ...
user avatar
  • 5,172

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