So I'm trying to include a dollar test in my program that checks if the value inputted by the user is a possible dollar amount. I'm having troubles with it subtracting .01 in the while-loop. The idea is if they enter a value with 3 decimal places like 2.345, it'll catch it and have the input a valid number. Does anyone have any advice on how to fix this problem?
Scanner input = new Scanner(System.in);
double dollar = 0;
System.out.print("Please enter a dollar amount: ");
dollar = input.nextDouble();
while (dollar != 0){
dollar -= .01;
if (dollar < 0)
{System.out.print("Please enter a valid dollar amount: ");
dollar = input.nextDouble();
}
System.out.println(dollar);
}
}