我以前曾发布过这个程序,但意识到我通过添加循环和其他什么东西想多了。我已经把它配对了一点,但仍然遇到问题。该程序应该是一个改变机器。在用户输入价格后,程序应将其四舍五入到最接近的美元,然后输出将分配多少零钱以及哪些硬币的数量。此时的输出完全错误。我对编程很陌生,我很茫然。
package changemachine;
import java.util.Scanner;
import java.text.*;
public class Main
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter Purchase Price: ");
double price = scan.nextDouble();
int newPrice = (int)(price*100);
int paid = (int)(newPrice+1);
int change = (int)(paid - newPrice);
int quarters = (int)(change/25);
int dimes = (int)((change%25)/10);
int nickels = (int)((change%25%10)/5);
int pennies = (int) (change%25%10%5);
System.out.println("Dispensing: " + quarters + " Quarters,"
+ dimes + "Dimes," + nickels + "Nickels,"
+ pennies + "Pennies.");
System.out.println("Program written by Ashley ");
}
}