I have to create a vending machine that adjusts its price according to the temperature for my AP computer science class. The only problem that I have right now is that the machine isn't supposed to accept pennies, so I tried to take the user's input (amount of money) and modulo it by .05
and if that results in anything other than 0.0
it re-runs the program and prompts the user for an input that doesn't contain pennies; however, even if I enter a number that, if modded by .05
, does result in 0.0
, it still tells the user "No pennies please." The user input is a double
and not an int
and I don't know whether or not that affects it or not but I'll attach something similar to what the code looks like:
double userMoney = scan.nextDouble
double penny = userMoeny % .05
if (penny != 0.0)
says something that says no pennys
else
executes the rest of the code
I understand that wasn't properly formatted but I don't have access to the raw code as of right now.
As I said before, no matter what I enter, when I mod it by .05
it always seems to come out to be anything but 0.0
, even if it should be.