这道VB程序题目做出来后发现语句基本正确,就是有一些小问题,请各位看一看!
我们大家一起来试营一家有80间套房的旅馆,看看知识如何转化为财富。经调查得知,若我们把每日租金定价为160元,则可客满;而租金每涨20元,就会失去3位客人。每间住了人的客...
我们大家一起来试营一家有80间套房的旅馆,看看知识如何转化为财富。 经调查得知,若我们把每日租金定价为160元,则可客满;而租金每涨20元,就会失去3位客人。 每间住了人的客房每日所需服务、维修等项支出共计40元。 问题:我们该如何定价才能赚最多的钱?
答:
Dim sum, room, rent, customer, p, c, maintain As Integer
Dim last_sum, last_rent, last_room As Integer
Private Sub Command1_Click()
last_sum = 0
For rent = 160 To 1000 Step p
customer = customer - c
room = customer
sum = rent * room - maintain * room
If last_sum < sum Then
last_sum = sum
last_rent = rent
last_room = room
End If
Next rent
Label2.Caption = "最高租金为" & last_rent & "元;最多用房间数为" & last_room & ";最大收入为" & last_sum & "元。"
End Sub
Private Sub Form_Load()
room = 80
customer = 80
rent = 160
maintain = 40
p = 20
c = 3
End Sub
正确答案是:最高租金为360元,最多用房间数为50,最大收入为16000元,谢谢。 展开
答:
Dim sum, room, rent, customer, p, c, maintain As Integer
Dim last_sum, last_rent, last_room As Integer
Private Sub Command1_Click()
last_sum = 0
For rent = 160 To 1000 Step p
customer = customer - c
room = customer
sum = rent * room - maintain * room
If last_sum < sum Then
last_sum = sum
last_rent = rent
last_room = room
End If
Next rent
Label2.Caption = "最高租金为" & last_rent & "元;最多用房间数为" & last_room & ";最大收入为" & last_sum & "元。"
End Sub
Private Sub Form_Load()
room = 80
customer = 80
rent = 160
maintain = 40
p = 20
c = 3
End Sub
正确答案是:最高租金为360元,最多用房间数为50,最大收入为16000元,谢谢。 展开
展开全部
你的问题主要出在For循环中
第一次循环时,rent=160,你就直接把顾客数-3,即customer = customer - c
这时客户数已经是77了,如果用这个客户数去算收入就错了(因为租金为160时,是80人住,收入也是按80人算)。
应该是先算好收入,再把顾客数-3就可以了。
程序改写很简单,将customer = customer - c移到End If的后面一行就可以了。
另外,你变量定义很是个问题。
Dim sum, room, rent, customer, p, c, maintain As Integer
这样,就只有maintain是整型,其它都是变体类型,如果要都定义成整型,则应写作:
Dim sum As Integer, room As Integer, rent As Integer, customer As Integer, p As Integer, c As Integer, maintain As Integer
还有,p,c,maitain都是固定不变的,建议定义成常量(用const)
第一次循环时,rent=160,你就直接把顾客数-3,即customer = customer - c
这时客户数已经是77了,如果用这个客户数去算收入就错了(因为租金为160时,是80人住,收入也是按80人算)。
应该是先算好收入,再把顾客数-3就可以了。
程序改写很简单,将customer = customer - c移到End If的后面一行就可以了。
另外,你变量定义很是个问题。
Dim sum, room, rent, customer, p, c, maintain As Integer
这样,就只有maintain是整型,其它都是变体类型,如果要都定义成整型,则应写作:
Dim sum As Integer, room As Integer, rent As Integer, customer As Integer, p As Integer, c As Integer, maintain As Integer
还有,p,c,maitain都是固定不变的,建议定义成常量(用const)
展开全部
正确答案是:最高租金为360元,最多用房间数为50,最大收入为16000元
你这个也不对吧,360*50=18000元吧。
用我下面的就可以了,得出是最高租金为320元,最多用房间数为50,最大收入为16000元
代码如下,一个COMMAND1搞定:
Private Sub Command1_Click()
Dim room, mrzj, kr, wh, sr As Integer
Dim room1, mrzj1, sr1 As Integer
room = 80 '房间数量
mrzj = 120 '每日的租金收入要去掉维护费用 160-40=120元
kr = 80 '客人数量
sr = room * mrzj '收入=房间数量*每日的租金
'最佳设置初始化
room1 = room
mrzj1 = mrzj
sr1 = sr
'Label1.Caption = "租金" & Format(mrzj1, "0") & " 房间" & Format(room1, "0") & " 收入" & Format(sr1, "0")
Do While (kr > 0) '继续条件,还有客人,没有客人了还玩个屁啊
mrzj = mrzj + 20 '租金每涨20元
kr = kr - 3 '就会失去3位客人
room = room - 3 '使用的房间就会少三间
sr = room * mrzj '收入=房间数量*每日的租金
'Label1.Caption = Label1.Caption & vbCrLf & "租金" & Format(mrzj, "0") & " 房间" & Format(room, "0") & " 收入" & Format(sr, "0")
If sr1 < sr Then
room1 = room
mrzj1 = mrzj
sr1 = sr
End If
Loop
MsgBox "最高租金为:" & Format(mrzj1, "0") & "元 最多用房间数为:" & Format(room1, "0") & "间 最大收入为:" & Format(sr1, "0") & "元", vbOKOnly, "最佳方案"
End Sub
你这个也不对吧,360*50=18000元吧。
用我下面的就可以了,得出是最高租金为320元,最多用房间数为50,最大收入为16000元
代码如下,一个COMMAND1搞定:
Private Sub Command1_Click()
Dim room, mrzj, kr, wh, sr As Integer
Dim room1, mrzj1, sr1 As Integer
room = 80 '房间数量
mrzj = 120 '每日的租金收入要去掉维护费用 160-40=120元
kr = 80 '客人数量
sr = room * mrzj '收入=房间数量*每日的租金
'最佳设置初始化
room1 = room
mrzj1 = mrzj
sr1 = sr
'Label1.Caption = "租金" & Format(mrzj1, "0") & " 房间" & Format(room1, "0") & " 收入" & Format(sr1, "0")
Do While (kr > 0) '继续条件,还有客人,没有客人了还玩个屁啊
mrzj = mrzj + 20 '租金每涨20元
kr = kr - 3 '就会失去3位客人
room = room - 3 '使用的房间就会少三间
sr = room * mrzj '收入=房间数量*每日的租金
'Label1.Caption = Label1.Caption & vbCrLf & "租金" & Format(mrzj, "0") & " 房间" & Format(room, "0") & " 收入" & Format(sr, "0")
If sr1 < sr Then
room1 = room
mrzj1 = mrzj
sr1 = sr
End If
Loop
MsgBox "最高租金为:" & Format(mrzj1, "0") & "元 最多用房间数为:" & Format(room1, "0") & "间 最大收入为:" & Format(sr1, "0") & "元", vbOKOnly, "最佳方案"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-11-17
展开全部
Dim sum, room, rent, customer, p, c, maintain As Integer
Dim last_sum, last_rent, last_room As Integer
Private Sub Command1_Click()
last_sum = 0For rent = 160 To 1000 Step p
room = customer
sum = rent * room - maintain * room
If last_sum < sum Then
last_sum = sum
last_rent = rent
last_room = room
End If
customer = customer - c '把这一句放到这
Next rent
Label2.Caption = "最高租金为" & last_rent & "元;最多用房间数为" & last_room & ";最大收入为" & last_sum & "元。"
End Sub
Private Sub Form_Load()
room = 80
customer = 80
rent = 160
maintain = 40
p = 20
c = 3
End Sub
Dim last_sum, last_rent, last_room As Integer
Private Sub Command1_Click()
last_sum = 0For rent = 160 To 1000 Step p
room = customer
sum = rent * room - maintain * room
If last_sum < sum Then
last_sum = sum
last_rent = rent
last_room = room
End If
customer = customer - c '把这一句放到这
Next rent
Label2.Caption = "最高租金为" & last_rent & "元;最多用房间数为" & last_room & ";最大收入为" & last_sum & "元。"
End Sub
Private Sub Form_Load()
room = 80
customer = 80
rent = 160
maintain = 40
p = 20
c = 3
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询