0

I received great advice and they told me go back and study and fix my brackets and this is my new code

include

include

int Minutes;

int main(void) { do { int Minutes = get_int();
printf("minutes: %i\n", Minutes); Minutes = Minutes * 12;

    int Bottles = Minutes * 12;
    printf("Bottles: %i\n", Bottles);

    printf ("You took %i Minutes in the shower which means that you have used %i Bottles of water\n", Minutes, Bottles);
}
while ( Minutes < 0);

}

but I am getting one error now

water.c:10:13: error: declaration shadows a variable in the global scope [-Werror,-Wshadow] int Minutes = get_int();

water.c:4:5: note: previous declaration is here int Minutes; ^

1
  • 1
    As an aside, make sure to post the code blocks correctly else it can be tough for others to understand, especially relating to lines.
    – AvidUrner
    Commented Aug 16, 2017 at 0:28

1 Answer 1

0

Your first declaration of variable int Minutes; on line 4 is attempting to be overwritten or "shadowed" by int Minutes = get_int(); on line 10. Since Minutes has already been declared as an int globally on line 4, there is no reason to declare it as an int again on line 10. Further, the get_int() function knows to assign its input to Minutes as an int.

You're also going to run into trouble with Minutes = Minutes * 12;. As you wrote it you are trying to assign a variable with itself * 12. Go back and check the specification bit regarding the 1:12 ratio.

1
  • The next question is this: What is the compelling need for a global variable here? Best practice is not to use global variables without a very good reason.
    – Cliff B
    Commented Aug 16, 2017 at 0:45

You must log in to answer this question.

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