即使我没有触及它,值也会随机变化。

时间:2016-07-12 08:14:20

标签: function cobol

perform 200-ctTerm.

    100-cTrans.
    *> open error file
     open output error-file
    *> change values of cus bal and prodprice for comp
     compute cCusBal = function numval(lst-cusBal) end-compute.
     compute cProdPrice = function numval(lst-prodPrice) end-compute.
     display "CUST BAL1: "cCusBal *> OUPUT: 05815 the corrected value

    *> start of transaction comp

     if lst-prodStock = 0 then
    *> 0 items in stock, update error-file
       set eProdNum to lst-prodNum
       set zStock to "out of prod"
       set eTransNum to lst-transCusNum
       set NBH to "could not be handled"
       write out-error end-write *> example of output to error-file - prodnum of out prod cusNum could not be handled

       close error-file *> close file
       go to 200-ctTerm

     end-if.

       *> order > stock
     if lst-transOrder is greater than lst-prodStock then
          compute tPrice = lst-prodStock * cProdPrice *> transaction only consists of # in stock
          if lst-prodStock is greater or equal lst-transOrder then
           compute tPrice = lst-transOrder * cProdPrice *> get orginal total price
           *> check order codes and then apply codes
           evaluate lst-transCode
               when "A"
                   compute discount = tPrice * .10
                   compute tPrice = tPrice - discount
                   compute lst-prodStock = lst-prodStock - lst-prodStock *>stock now at 0
               when "B"
                   compute discount = tPrice * .20
                   compute tPrice = tPrice - discount
                   compute lst-prodStock = lst-prodStock - lst-prodStock *>stock now at 0
               when "C"
                   compute discount = tPrice * .25
                   compute tPrice = tPrice - discount
                   compute lst-prodStock = lst-prodStock - lst-prodStock *>stock now at 0

               when "D"
                   if lst-transOrder greater or equal 3 then
                       compute tPrice = tPrice - cProdPrice *> if order > 3 get one free
                       compute lst-prodStock = lst-prodStock - lst-prodStock *>stock now at 0
                   end-if
               when "E" 
                   if lst-transOrder greater or equal 1 then
                       compute BOGO = lst-transOrder / 2  *> check to see how many free
                       compute tPrice = tPrice - cProdPrice * BOGO *> apply buy one get one
                       compute lst-prodStock = lst-prodStock - lst-prodStock *>stock now at 0
                   end-if
               when "Z"
                   compute lst-prodStock = lst-prodStock - lst-prodStock *>stock now at 0
               end-evaluate 
     end-if.

      *> stock >= order
       if lst-prodStock is greater or equal lst-transOrder then
           compute tPrice = lst-transOrder * cProdPrice *> get orginal total price
           *> check order codes and then apply codes
           evaluate lst-transCode
               when "A"
                   compute discount = tPrice * .10 *>get discount
                   compute tPrice = tPrice - discount *>update total price of transaction.
                   compute lst-prodStock = lst-prodStock - lst-transOrder *>update stock

               when "B"
                   compute discount = tPrice * .20 *>get discount
                   compute tPrice = tPrice - discount *>update total price of transaction.
                   compute lst-prodStock = lst-prodStock - lst-transOrder *>update stock
               when "C"
                   compute discount = tPrice * .25 *>get discount
                   compute tPrice = tPrice - discount *>update total price of transaction.
                   compute lst-prodStock = lst-prodStock - lst-transOrder *>update stock

               when "D"
                   if lst-transOrder greater or equal 3 then
                       compute tPrice = tPrice - cProdPrice *> if order > 3 get one free
                       compute lst-prodStock = lst-prodStock - lst-transOrder *>update stock
                   end-if
               when "E" 
                   if lst-transOrder greater or equal 1 then
                       compute BOGO = lst-transOrder / 2  *> check to see how many free
                       compute tPrice = tPrice - cProdPrice * BOGO *> apply buy one get one
                       compute lst-prodStock = lst-prodStock - lst-transOrder *>update stock
                   end-if
               when "Z"
                   compute lst-prodStock = lst-prodStock - lst-transOrder *>update stock
               end-evaluate 
      display "total Price: "tPrice
      display "CUS BAL2 "cCusBal *> OUTP: 05810 - randomly changed
      compute cCusBal = cCusBal + tPrice *> which cause this to be wrong
      display "New balace: "cCusBal 
      move cCusBal to lst-cusBal

     end-if.
     go to 200-ctTerm
    exit.

我计算cCusBal并获得正确答案(lst-cusBal = 058.15),然后在我执行计算部分后,我不接触cCusBal,其值从05815随机变化到05810.这会影响计算sCusBal + tPrice和我的预期值为5。我不知道这里发生了什么,任何帮助将不胜感激

0 个答案:

没有答案