Javascript js自动取款机的货币面额程序,可以灵活地处理和分发最低面值的钞票

Javascript js自动取款机的货币面额程序,可以灵活地处理和分发最低面值的钞票,javascript,typescript,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) { v

该代码应该能够处理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);
var h=5;
var f=2;
var t=1;
变量IFAMTLESTN2000=IFAMTLESTN2000(n){
无功温度;
如果(n<500){
h+=(n/100);
返回{
H
}
}否则如果(n>=500&&n<2000){
f+=n/500;
h+=(n-500)/100;
返回{
H
F
}
}否则{
温度=n-1500;
如果(温度<500){
h+=(温度/100);
返回{
H
}
控制台日志('100:'+h);
}否则{
f+=1;
h+=(温度-500)/100;
控制台日志('500:'+f);
控制台日志('100:'+h);
返回{
F
H
}
}
}
}
var IFamtgreeterThan2000=(n)=>{
var h=0;
var f=0;
var t=0;
var-tt=0;
无功温度;
如果(n<2000){
tt+=(n/2000);
}
否则如果(n>=2000&&n<10000){
f+=n/500;
h+=(n-500)/100;
}
否则{
温度=n-1500;
如果(温度<500){
h+=(温度/100);
}
否则{
f+=1;
h+=(温度-500)/100;
}
}
}
var checkAmt=(n)=>{
如果(n<100 | |(n%100)>0){
console.log(“无效金额:小于100”);
}否则{
如果(n>20000){
控制台日志(“ATM现金限额超过”);
}否则{
如果(n 500)
温度=温度-(1000*(t-1));
IFAMTLESTHN2500(温度);
控制台日志(h+“x100”);
控制台日志(f+“x 500”);
控制台日志(t+“x 1000”);
}
}
}
}
支票金额(2500);

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

这将根据您输入的金额打印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);

希望这对您有所帮助

这将涵盖您的所有案例

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);
功能分配箱(输入装载){
var注释=[];
var余额=3000;
如果(输入量!==0&&inputAmount%100==0&&inputAmount余额){
console.log(“您的帐户余额不足”);
}
否则如果(输入量%100!=0 | |输入量<100){
console.log(“输入的金额无效,金额应为100的倍数”);
}
}
分发箱(2600);
amtArray=[2000500100];//你想找到的面额。
for(设i=0;i
根据数量,您可以调整逻辑

希望这有帮助:)

//ATM现金面额//此方法中已提供现金输入值//您可以使用输入流方法输入用户输入值
公营教派
{
公共静态void main(字符串args[])//引发IOException
{
int notes[]={500020001000500100};//存储数组中的所有面额
整数金额=27000;
int copy=amount;//复制金额
int totalNotes=0,count=0;
System.out.println(“\n现金面额:\n”);

对于(inti=0;iJavascript中的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);

函数countCurrency(金额){
var注释=[2000500200100];
var noteCounter=[0,0,0,0];
对于(变量i=0;i<4;i++){
如果(金额>=附注[i]){
票据计数器[i]=数学下限(金额/票据[i]);
金额=金额-票据计数器[i]*票据[i];
}
}
//印钞面额
console.log(“面额计数:”);
对于(var j=0;j<4;j++){
如果(记事本计数器[j]!==0){
log(notes[j]+“:”+noteccounter[j]);
}
}
}
国家货币(3300);
下面是一个工作示例

请解释您的程序有什么问题(输入、当前输出、预期输出)事实上,我是js新手,所以谷歌搜索了一下,在java中找到了一个代码,试图将其转换为js。但是没有任何效果!!@user202729有任何帮助吗?直到你把你的问题做得更好。到底是什么不起作用?如果有错误消息,它们是什么?如果你的函数
inputAmount
超过3000,它将进行计算问题是的。你可以在这里添加更多的检查,我正在检查输入量!==0编辑你的答案,使用
Math.floor
而不是
Math.round
,对不起,如果你这样做了MindThank@Koushikredyu,但这不是解决方案…它不能处理每一笔高达20000的金额,并且应该显示适当的面额…不@koushik Reddy U,3000后,此代码返回-1,-2值,这不是最佳值。检查此JSFIDLE,请参阅浏览器控制台中的输出。
//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
 }
} 
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);