用于自动取款机的货币面额计划,可以灵活处理和分配最低票据

时间:2018-05-14 08:24:42

标签: javascript typescript

代码应该能够处理高达20000的任何金额,例如,假设当卡中的余额为3000时输入金额为2600.将输出如下: 新平衡 - 400 笔记: 2000 * 1 500 * 1 100 * 1

(仅三张纸币2000,500,100)和现金限额为20000

我是javascript世界的新手,我无法编写代码,任何人都可以帮助我吗???请!

var h = 5;
var f = 2;
var t = 1;


var ifAmtLessThn2000 = ifAmtLessThn2000(n) {
    var temp;
    if (n < 500) {
        h += (n / 100);
        return {
            h
        }
    } else if (n >= 500 && n < 2000) {
        f += n / 500;
        h += (n - 500) / 100;
        return {
            h,
            f
        }
    } else {
        temp = n - 1500;
        if (temp < 500) {
            h += (temp / 100);
            return {
                h
            }
            console.log('hundred : ' + h);
        } else {
            f += 1;
            h += (temp - 500) / 100;
            console.log('five hundred : ' + f);
            console.log('hundred : ' + h);
            return {
                f,
                h
            }
        }
    }
}


var ifAmtGreaterthan2000 = (n) => {
    var h = 0;
    var f = 0;
    var t = 0;
    var tt = 0;
    var temp;

    if (n < 2000) {
        tt += (n / 2000);
    }
    else if (n >= 2000 && n < 10000) {
        f += n / 500;
        h += (n - 500) / 100;
    }
    else {
        temp = n - 1500;
        if (temp < 500) {
            h += (temp / 100);
        }
        else {
            f += 1;
            h += (temp - 500) / 100;
        }
    }
}




var checkAmt = (n) => {
    if (n < 100 || (n % 100) > 0) {
        console.log("Invalid Amount : less than 100 ");
    } else {
        if (n > 20000) {
            console.log("ATM Cash Limit exceeds.");
        } else {
            if (n <= 2500) {
                ifAmtLessThn2500(n);
                console.log(h + " x 100");
                console.log(f + " x 500");
            } else {
                temp = n - 2500;
                t += temp / 1000;
                if (temp > 500)
                    temp = temp - (1000 * (t - 1));
                ifAmtLessThn2500(temp);
                console.log(h + " x 100");
                console.log(f + " x 500");
                console.log(t + " x 1000");
            }
        }
    }

}

checkAmt(2500);

很抱歉有一个愚蠢的程序,但我需要帮助,请任何人都可以给我一个typeScript代码的解决方案,在数组中返回req面额!!

5 个答案:

答案 0 :(得分:1)

import requests

根据数量可以调整逻辑。

希望这会有所帮助..:)

答案 1 :(得分:1)

Javascript 中的 ATM 面额程序。

在这里,它会找到与输入金额相加的不同面额纸币的最小数量。从最高面额的纸币到最低的纸币。

function countCurrency(amount) {
  var notes = [2000, 500, 200, 100];
  var noteCounter = [0, 0, 0, 0];

  for (var i = 0; i < 4; i++) {
    if (amount >= notes[i]) {
      noteCounter[i] = Math.floor(amount / notes[i]);
      amount = amount - noteCounter[i] * notes[i];
    }
  }
  // Print notes denomination
  console.log("Denomination Count:");
  for (var j = 0; j < 4; j++) {
    if (noteCounter[j] !== 0) {
      console.log(notes[j] + " : " + noteCounter[j]);
    }
  }
}

countCurrency(3300);

这是工作示例 https://codesandbox.io/s/atm-denomination-javascript-o0wb4?file=/src/index.js

答案 2 :(得分:0)

这将按照您输入的金额打印2000,500,100订单中的票据数量

function dispenseCase (inputAmount) {
 var notes = [];

  if(inputAmount !== 0) {
    var notes2000 = Math.round(inputAmount / 2000);
    var notes500 = Math.round((inputAmount - (notes2000 * 2000)) / 500 );
    var notes100 = Math.round((inputAmount - ((notes2000 * 2000) + (notes500 * 500))) / 100);

   notes.push(notes2000);
   notes.push(notes500);
   notes.push(notes100);

   console.log(notes);
  }
}

dispenseCase(2600);

希望这会有所帮助

答案 3 :(得分:0)

这将涵盖您的所有案件

function dispenseCase (inputAmount) {
 var notes = [];
 var balance = 3000;

  if(inputAmount !== 0 && inputAmount % 100 == 0 && inputAmount <= balance) {
    var notes2000 = Math.round(inputAmount / 2000);
    var notes500 = Math.round((inputAmount - (notes2000 * 2000)) / 500 );
    var notes100 = Math.round((inputAmount - ((notes2000 * 2000) + (notes500 * 500))) / 100);

   notes.push(notes2000);
   notes.push(notes500);
   notes.push(notes100);

   console.log("balance in you account = ", balance - inputAmount);
   console.log(notes);
  }
  else if (inputAmount > balance) {
   console.log("Insufficient balance in your account");
  }
  else if ( inputAmount % 100 != 0 || inputAmount < 100 ) {
   console.log( "Invalid amount entered, amount should be multiples of 100");
}
}

dispenseCase(2600);

答案 4 :(得分:0)

//ATM Cash Denominations //Cash Input Value Already been Provided in this method // You may use a input stream method to input a user input value

public class Denominations
{
 public static void main(String args[])//throws IOException
 {

 int notes[]={5000,2000,1000,500,100}; //storing all the denominations in an array
 int amount = 27000;

 int copy=amount; //Making a copy of the amount
 int totalNotes=0,count=0;

 System.out.println("\nATM CASH DENOMINATIONS: \n");

 for(int i=0;i<5;i++) //Since there are 5 different types of notes, hence we check for each note.
 {
 count=amount/notes[i]; // counting number of notes[i] notes
 if(count!=0) //printing that denomination if the count is not zero
 {
 System.out.println(notes[i]+"\tx\t"+count+"\t= "+notes[i]*count);
 }
 totalNotes=totalNotes+count; //finding the total number of notes
 amount=amount%notes[i]; //finding the remaining amount whose denomination is to be found
 }

 System.out.println("--------------------------------");
 System.out.println("TOTAL\t\t\t= "+copy); //printing the total amount
 System.out.println("--------------------------------");
 System.out.println("Total Number of Notes\t= "+totalNotes); //printing the total number of notes
 }
}