Hot answers tagged

3 votes

PSET1 - Water fails check50: "expected prompt for input, not exit code of 0"

One option would be to simply use the GetInt(); function in the cs50.h library since it already reprompts the user for input if they give bogus values. Or implement the feature yourself and use a ...
NullityNull's user avatar
2 votes
Accepted

water week 1 problem

Like I edited in my own problem and comment, I solved it. #include <stdio.h> #include <cs50.h> int main(void) { int bottle = 12; int num_bottles; printf("minutes: \n"); int ...
NewBie1234's user avatar
2 votes
Accepted

Infinite looping in hacker 1 - water

I like that you don't want to use CS50's tools and use tools that you are going to have available everywhere outside of CS50. I was reviewing your code. I tried to solve it with a fflush(stdin) line, ...
Ricardo David Antonetti's user avatar
2 votes

Infinite looping in hacker 1 - water

Yes, don't use scanf. You have a library that helps you avoid using scanf. The reason is probably related to the fact that scanf still keeps the string you input in its buffer and it won't empty it, ...
Irene's user avatar
  • 1,687
1 vote

water week 1 problem

Not really a good solution. What happens if someone enters bad input twice? You need a solution that will keep prompting for valid input until it is entered. Time to discover what a while loop is. ...
Cliff B's user avatar
  • 68.4k
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 ...
curiouskiwi's user avatar
  • 18.6k
1 vote

unused variable error

You should review the class material and google references for printf. Specifically, to print the value of a variable, you need a place marker in the print format string and the var name in the printf ...
Cliff B's user avatar
  • 68.4k
1 vote
Accepted

PSet 1, Trying to add a loop to Water

You'd need a loop only if you want to re-query the user. If minutes does not change within the loop, the result will always be the same. Also, while (minutes < 0, minutes == 0); is an empty loop, ...
Blauelf's user avatar
  • 20.9k
1 vote
Accepted

What is the proper way to use "do while" loop for Pset1 water

The do while loop tells the program to do these things in order: Do something - The code you put between the curly braces {statement(s)} will run at least once. The while condition between the ...
Ryan McCauley's user avatar
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 ...
SuperNovaCoder's user avatar
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 ...
MARS's user avatar
  • 5,169
1 vote
Accepted

(PSET 1) Creating functions for water.c. Dont understand how this function worked. (Contains pset answer)

A real answer is further down Take note to how I formatted your code according to CS50's style guide. Well formatted code is important if you expect others (or even yourself at a later date) to read ...
kluvin's user avatar
  • 1,223
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 ...
Iris Frenzy's 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 ...
mayure098's 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 ...
MARS's user avatar
  • 5,169

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