因此,我们的程序假设让用户输入一定数量的钱,然后生成他们得到多少零钱(四分之一,零点等),然后找回零钱后,该程序会要求用户输入是否想要再试一次还是不试。这是该程序似乎无法正常工作的地方,我需要帮助。这是我到目前为止的内容:
package week14;
import java.util.Scanner;
public class VendingMachine {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a whole number 1-99.\n I will find a combination of coins\n that equals that amount of change: ");
int coins = input.nextInt();
String answer = "yes";
while (answer.equals("yes")) {
if (coins >=1 && coins <= 99) {
int quarters = coins / 25;
int dimes = (coins%25) / 10;
int nickels = ((coins%25)%10) / 5;
int pennies = (((coins%25)%10)%5) / 1;
System.out.print(coins + " cents in coins can be given as\n"+quarters+" quarters\n"+dimes+" dimes\n"+nickels+" nickels\n"+pennies+" pennies\n");
System.out.print("Do you want to try again? ");
answer = input.nextLine();
answer = answer.toLowerCase();
System.out.print("\nEnter a whole number 1-99.\n I will find a combination of coins\n that equals that amount of change: ");
coins = input.nextInt();
}else {
System.out.print("Please enter between 1-99.\nEnter again: ");
coins = input.nextInt();
}
if(answer.equals("no")) {
System.out.println("\nThanks for using \"Change Maker\" program!");
break;
}
}
}
}