0

I've been trying to get this by myself for hours but I'm new to coding, so I don't really know how to fix this. When I call the cost again, it won't add the number I try to add and won't budge off of 0. I want the "cost" integer to add 1 to itself when the user inputs the word "Small".

1 Answers1

1

It looks like you're passing the cost to the function as a parameter, which for primitives (likeint or float) means that what you're working with inside the function is not the cost variable declared outside the function, but merely a copy with the same value. So when you increment the variable, you're actually incrementing the copy that was passed into the function.

The fix should be quite simple: just remove the cost parameter and you'll automatically be working with the global variable instead.

Also, it seems weird that you're calling a function (presumably) directly inside the class body which should normally give a compiler error.

linux_user36
  • 113
  • 1
  • 8