I have a problem with the water consumption code in pset 1.

  #include <cs50.h>
  #include <stdio.h>

  int main(void)

     int n = get_int();

An error message pops up for an unused or unidentified variable :

~/workspace/ $ make water
 clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -
 Werror -Wextra -Wno-sign-compare -Wshadow    water.c  -lcrypt -lcs50 -lm -o 
water.c:8:9: error: unused variable 'n' [-Werror,-Wunused-variable]
   int n = get_int();
1 error generated.
 make: *** [water] Error 1


  • Well, it is unused, indeed. Use it somehow – obesman Jun 18 '17 at 5:17

It's literally an unused variable. You are creating and initializing n, but you don't do anything with it after that. If you were to do anything with it, like incrementing it or printing it, the problem would go away.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance, ;-)

  • I want to take an integer from the user and add it to the Minutes: line , can you please rewrite the code for me to clarify the situation? – Hasan Alaa Nassr Jun 18 '17 at 16:17
  • I could, but I won't. This is the purpose of the exercise, to learn how to do exactly that. Besides, why do you need to have someone show you what you've already correctly done? Also, get in the habit of using meaningful variable names and not single letters: int minutes = get_int(); As for the error, just add some code to do something with the var you have just created and the error goes away! – Cliff B Jun 18 '17 at 19:27
  • Thank you very much – Hasan Alaa Nassr Jun 19 '17 at 1:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .