讨论:想实现混合运算
本帖最后由 vfhpai9 于 2009-6-19 18:34 编辑我已实现单步运算,但无法混合运算。
如:(A+B-E)*C/D
只能算出A+B的结果。
谢谢大哥大姐了,急用啊!!! 你怎么算的,代码贴出来看下? #include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global $lnzong,$Inzong,$nzong
Global $lgmao,$Igmao,$gmao
Global $lgche,$Igche,$gche
Global $lnkuang,$Inkuang,$nkuang
Global $lgkuang,$Igkuang
Global $lgshui,$Igshui,$gshui
Global $lnfei,$Infei,$nfei
Global $lgfei,$Igfei,$gfei
Global $lgshi,$Igshi,$gshi
Global $lG,$IG,$G2,$G3
Example1()
; example 1
Func Example1()
Local $msg
GUICreate("计算",1000,500,0,0); will create a dialog box that when displayed is centered
GUISetState(@SW_SHOW) ; will display an empty dialog box
$lnzong=GUICtrlCreateLabel("总只数",40,100,50,15)
$Inzong=GUICtrlCreateInput("",20,120,70,15)
$lgmao=GUICtrlCreateLabel("毛重",120,100,50,15)
$Igmao=GUICtrlCreateInput("",100,120,70,15)
$lgkuang=GUICtrlCreateLabel("筐重",200,100,50,15)
$Igkuang=GUICtrlCreateInput("",180,120,50,15)
$lnkuang=GUICtrlCreateLabel("筐的数量",260,100,70,15)
$Inkuang=GUICtrlCreateInput("",260,120,50,15)
$lgche=GUICtrlCreateLabel("车重",340,100,70,15)
$Igche=GUICtrlCreateInput("",320,120,70,15)
$lgshui=GUICtrlCreateLabel("水杂扣重",420,100,70,15)
$Igshui=GUICtrlCreateInput("",400,120,70,15)
$lnfei=GUICtrlCreateLabel("废弃只数",500,100,70,15)
$Infei=GUICtrlCreateInput("",490,120,70,15)
$lgfei=GUICtrlCreateLabel("废弃重量",580,100,70,15)
$Igfei=GUICtrlCreateInput("",570,120,70,15)
$lgshi=GUICtrlCreateLabel("食污扣重",660,100,70,15)
$Igshi=GUICtrlCreateInput("",650,120,70,15)
$lG=GUICtrlCreateLabel("净重",730,100,70,15)
$IG=GUICtrlCreateInput("",730,120,70,15)
; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
do
$lnzong=GUICtrlRead($Inzong)
$lgmao=GUICtrlRead($Igmao)
$lnkuang=GUICtrlRead($Inkuang)
$lgkuang=GUICtrlRead($Igkuang)
$lgshui=GUICtrlRead($Igshui)
$lnfei=GUICtrlRead($Infei)
$lgche=GUICtrlRead($Igche)
$lgfei=$lgmao/$lnzong+$lgkuang; 此步混合运算出错
GUICtrlSetData($Igfei,$lgfei)
Until $lnzong<0&$lnkuang<0&$lgmao<0
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
EndFunc ;==>Example1 #include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("混合运算示例", 271, 215, 192, 124)
$Input1 = GUICtrlCreateInput("1", 48, 24, 121, 21)
$Input2 = GUICtrlCreateInput("2", 48, 56, 121, 21)
$Input3 = GUICtrlCreateInput("2", 48, 88, 121, 21)
$Input4 = GUICtrlCreateInput("4", 48, 120, 121, 21)
$Input5 = GUICtrlCreateInput("5", 48, 151, 121, 21)
$Button1 = GUICtrlCreateButton("混合运算", 177, 150, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$a=GUICtrlRead($Input1)
$b=GUICtrlRead($Input2)
$c=GUICtrlRead($Input3)
$d=GUICtrlRead($Input4)
$e=GUICtrlRead($Input5)
$result = ($a+$b-$c)*$d/$e
MsgBox('','',$result)
EndSwitch
WEnd
可以混合运算啊
看结果:
你的代码也没有什么错误啊 搞不懂
(1+2-2) * 4 / 5 难道不是等于0.8吗?汗 谢谢啊,我再试试!!! 问题已解决,谢谢了各位了!!!错在循环语句,用Switch循环语句即可!!! 1# vfhpai9
页:
[1]