求:数学公式“买M送N”或程序实现方法

发布网友 发布时间:2022-04-23 20:21

我来回答

3个回答

热心网友 时间:2023-09-01 05:14

可以用这种方法:假设x:入房人数 ,M:买几 ,N:送几 ,则下面的函数可返回收费人数:
Private Function f(ByVal x As Integer, ByVal M As Integer, N As Integer) As Integer
Dim a As Integer, b As Integer, c As Integer
a = (x \ (M + N)) * M
b = (x Mod (M + N))
If b > M Then
c = M
Else
c = b
End If
f = a + c
End Function

热心网友 时间:2023-09-01 05:15

设来了k个人,实行买M送N优惠,应该收的钱B
if k Mod (M+N)=0 then
B=k/(M+N)*M
elseif k Mod (M+N)<=M then
B=(k\(M+N)-1)*M + (k Mod (M+N))
elseif k Mod (M+N) >M then
B=k\(M+N)*M
endif
话说下次我来你们店能给点什么优惠吗?

热心网友 时间:2023-09-01 05:15

'以下代码通用性强。
'规则:买M送N,来了K人,应收费tCount人

'此处以买3送1为例,你可以修改为实际规则。其他代码不变tCount即为收费人数。

Dim M As Integer, N As Integer, K As Integer
Dim t As Integer, tt As Integer
Dim tCount As Integer
M = 3
N = 1
K = 5
t = K
For t = t To 0 Step -M
tCount = tCount + M
tt = t - M
t = t - IIf(tt > 0, N, 0)
Next
tCount = tCount + t
MsgBox "收费规则:买" & M & "送" & N & vbNewLine & "共来了" & K & "人" & vbNewLine & "应收费" & tCount & "人。"

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com