samedi 20 février 2016

Eclipse, I keep subtracting a while-loop value, and it won't give me the correct answer

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.

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);
    }
}

Aucun commentaire:

Enregistrer un commentaire