【问题标题】:Calculate change in ActionScript 2计算 ActionScript 2 中的变化
【发布时间】:2014-03-03 14:37:05
【问题描述】:

在学校给我做了一个练习,我必须根据他们必须支付的金额和他们已经支付的金额来计算要给某人的零钱。但是,我遇到了一个小问题,因为我无法输入其中的 for 来验证是否可以进行更改。

我做错了什么?

on (release){
//Defines variables
var nDespesa:Number = parseInt(caixaDespesa.text);
var nPago:Number = parseInt(caixaPago.text);
var nTroco:Number = nPago - nDespesa;

//Defines currency
var aDinheiro:Array = [500, 200, 100, 50, 20, 10, 5, 2, 1, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01];

//Defines the number of each note/coin to receive
var aReceber:Array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

//Verifies if the amount paid is bigger than the amount in debt
if(nPago > nDespesa){
    //Shows the change on the screen
    caixaMsg.text = "O troco será de " + nTroco + " euros";

    //Calculates the number of times each note/coin sould be given by matching the array positions
    for(var i:Number=0; i<aDinheiro.lenght; i++)
    {
        trace("Entrou no for");
        while(nTroco > aDinheiro[i]){
            trace("Entrou no while");
            aReceber[i]++;
            trace(aReceber[i]);
            nTroco -= aDinheiro[i];
            trace(nTroco);
        }
    }
}
else{
    //Shows on the screen that it's not possible to calculate the change because the debt is bigger than the amount paid
    caixaMsg.text = "O valor pago não corresponde ao valor da dívida";
}

//Shows the number of times each note/coin sould be given on the corresponding box 
caixa1c.text = aReceber[14];
caixa2c.text = aReceber[13];
caixa5c.text = aReceber[12];
caixa10c.text = aReceber[11];
caixa20c.text = aReceber[10];
caixa50c.text = aReceber[9];
caixa1e.text = aReceber[8];
caixa2e.text = aReceber[7];
caixa5e.text = aReceber[6];
caixa10e.text = aReceber[5];
caixa20e.text = aReceber[4];
caixa50e.text = aReceber[3];
caixa100e.text = aReceber[2];
caixa200e.text = aReceber[1];
caixa500e.text = aReceber[0];

}

【问题讨论】:

    标签: flash actionscript actionscript-2 flash-cs5


    【解决方案1】:

    仅仅是因为你拼错了length吗?

    for(var i:Number=0; i<aDinheiro.lenght; i++)
    

    应该是;

    for(var i:Number=0; i<aDinheiro.length; i++)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多