Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CalculateChange {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double price, provided, change;
- //System.out.print("Enter the purchase price:");
- price = Double.parseDouble(scanner.nextLine()) * 100;
- //System.out.print("Enter the amount given by the customer:");
- provided = Double.parseDouble(scanner.nextLine()) * 100;
- if (provided > price) {
- change = provided - price;
- double ones = change / 100;
- if (ones > 0) {
- change = change % 100;
- System.out.println(Math.floor(ones) + "x 1 lev");
- }
- double fifty = change / 50;
- if (fifty > 0) {
- change = change % 50;
- System.out.println(Math.floor(fifty) + " x 50 stotinki");
- }
- double twenty = change / 20;
- if (twenty > 0) {
- change = change % 20;
- System.out.println(Math.floor(twenty) + " x 20 stotinki");
- }
- double ten = change / 10;
- if (ten > 0) {
- change = change % 10;
- System.out.println(Math.floor(ten) + " x 10 stotinki");
- }
- double five = change / 5;
- if (five > 0) {
- change = change % 5;
- System.out.println(Math.floor(five) + " x 5 stotinki");
- }
- double two = change / 2;
- if (five > 0) {
- change = change % 2;
- System.out.println(Math.floor(two) + " x 2 stotinki");
- }
- double one = change;
- if (one > 0) {
- change = change % 1;
- System.out.println(Math.floor(one) + " x 1 stotinka");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment