2012年11月5日 星期一

百貨公司打折程式

豪慷慨百貨公司週年慶的打折策略,吸引了許多客人上門,因此公司決定再回饋客戶,當客戶消費超過2000 元時打折,消費超過5000 元時打折,消費超過10000 元時打55 折。請幫該公司寫出一個新的收銀台程式,輸入顧客購買總金額後,計算顧客實際需付的錢。

輸入說明:
購買金額n

輸出說明:
實付金額

輸入範例:
3000
6000
12000

輸出範例:
2100
3600
6600

4 則留言:

  1. Dim money As Long
    Dim countt As Boolean
    Private Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As 2
    Do
    Input #1, money
    If money > 10000 And countt = False Then money = money * 0.55: countt = True
    If money > 5000 And countt = False Then money = money * 0.6: countt = True
    If money > 2000 And countt = False Then money = money * 0.7: countt = True
    Print #2, money
    countt = False
    Loop Until EOF(1)
    Close #2
    Close #1
    End Sub

    回覆刪除
  2. Dim money As Long
    Dim countt As Boolean
    Private Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As 2
    Me.Hide
    Do
    Input #1, money
    Select Case money
    Case Is >= 10000
    money = money * 0.55
    Case Is >= 5000
    money = money * 0.6
    Case Is >= 2000
    money = money * 0.7
    End Select
    Print #2, money

    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  3. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Do Until EOF(1)
    Input #1, n
    If n > 2000 And n <= 5000 Then t = n * 0.7
    If n > 5000 And n <= 10000 Then t = n * 0.6
    If n > 10000 Then t = n * 0.55
    Print #2, t
    Loop
    Close
    Close
    End
    End Sub

    回覆刪除
  4. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Do
    Input #1, n
    Select Case n
    Case Is > 10000
    Print #2, n * 0.55
    Case Is > 5000
    If n <= 10000 Then Print #2, n * 0.6
    Case Is > 2000
    If n <= 5000 Then Print #2, n * 0.7
    Case Else
    Print #2, n
    End Select
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除