# a simple calculator

## Recommended Posts

I need help with writing some code.

i want a gui 100 X 100 with a button "Go".

Clicking on it will open a window with a place to enter a "number".

after entering the "Number" and click next it will do the next calculate:

"Number" \ 9 * 6

for example if the number is 9 so:

9 \ 9 * 6 = 6

and after i will enter the number it will give me the answer.

and sry for my bad english.

##### Share on other sites

Use:

```GUICreate  ;for creating a gui
GUICtrlCreateButton ; for adding a button
InputBox   ;for user to enter the number
MsgBox     ;to display the calculation you made with the number```
Edited by darkmaster071

##### Share on other sites

```#include <GUIConstants.au3>

\$Form1 = GUICreate("Form1", 321, 426, 192, 124)
\$Input1 = GUICtrlCreateInput("", 16, 40, 281, 21)
\$Button1 = GUICtrlCreateButton("Button1", 208, 96, 89, 25, 0x00020000)
\$Label1 = GUICtrlCreateLabel("No#", 16, 16, 36, 17)
GUISetState(@SW_SHOW)

While 1
\$nMsg = GUIGetMsg()
Switch \$nMsg
Case \$GUI_EVENT_CLOSE
Exit
Case \$Button1
MsgBox(0, "", GUICtrlRead(\$Input1) / 9 * 6)
EndSwitch
WEnd```

##### Share on other sites

Do you want your calculator to have the capability of determining the appropriate order of operations?

For example, if Number is 3 in the expression 2 + Number * 2, you should get 8 [2+ (Number*2)] and not 10 [(2+Number)*2].

If you want to avoid this issue, you can just have your calculator work with only two numbers at a time.

##### Share on other sites

Do you want your calculator to have the capability of determining the appropriate order of operations?

For example, if Number is 3 in the expression 2 + Number * 2, you should get 8 [2+ (Number*2)] and not 10 [(2+Number)*2].

If you want to avoid this issue, you can just have your calculator work with only two numbers at a time.

how can i do that :S?

##### Share on other sites

how can i do that :S?

If you're new to programming it will be a pain in the behind. You will find a lot better help than I can ever give you online; google is your friend. Search for 'evaluating infix expressions' or something like that--an infix expression is the type of expression you are trying to evaluate.

for example, infix expression: 3 + 2*5 + 1

postfix expression (AKA RPN): 3 2 5 * + 1 +

The algorithm i've previously implemented in C++ involved converted the infix expression to a postfix expression, and then evaluated the result.

If you only work with two numbers at a time like windows calculator, you can avoid all this hassle. For instance,

say you type 2*3 in your calculator... you can evaluate the result next time you press the equals sign or any operation sign.

2*5 + (displys result = 10) 2 + (displays result 12) 1 = (displays result 13)

I hope that made sense :S

##### Share on other sites

```#include <GUIConstants.au3>

\$Form1 = GUICreate("Form1", 321, 426, 192, 124)
\$Input1 = GUICtrlCreateInput("", 16, 40, 281, 21)
\$Button1 = GUICtrlCreateButton("Button1", 208, 96, 89, 25, 0x00020000)
\$Label1 = GUICtrlCreateLabel("No#", 16, 16, 36, 17)
GUISetState(@SW_SHOW)

While 1
\$nMsg = GUIGetMsg()
Switch \$nMsg
Case \$GUI_EVENT_CLOSE
Exit
Case \$Button1
MsgBox(0, "", GUICtrlRead(\$Input1) / 9 * 6)
EndSwitch
WEnd```

thx alot!

can anyone help me add a combobox with 3 option.

every option will change the "second" number in the calculation.

option 1 - "9"

option 2 - "12"

oprion 3 - "14"

example:

number1 \ number 2 * 6

ty very much!!!

up, help plz.

## Create an account

Register a new account

×

• Wiki

• Back

• Git