Computer Science Canada calculator using GUI |
Author: | gtahunter [ Fri May 11, 2007 4:08 pm ] |
Post subject: | calculator using GUI |
here is a very simple calculator program that can only add...subtract...divide or mutiply 2 numbers at once...i havnt gotten the clear screen button working yet...and there is probobly an easier way to make it..so any sugestions are greatly appreciated u can copy and paste...or just download it...w/e import GUI var x, y, b : int var num1 : int := 0 var num2 : int := 0 var answer : real var op: string var click:int:=0 procedure zero if click=1 then num2 +=0 put "0" .. end if if click=0 then click+=1 num1 +=0 put "0" .. end if end zero procedure one if click=1 then num2 +=1 put "1" .. end if if click=0 then click+=1 num1 +=1 put "1" .. end if end one procedure two if click=1 then num2 +=2 put "2" .. end if if click=0 then click+=1 num1 +=2 put "2" .. end if end two procedure three if click=1 then num2 +=3 put "3" .. end if if click=0 then click+=1 num1 +=3 put "3" .. end if end three procedure four if click=1 then num2 +=4 put "4" .. end if if click=0 then click+=1 num1 +=4 put "4" .. end if end four procedure five if click=1 then num2 +=5 put "5" .. end if if click=0 then click+=1 num1 +=5 put "5" .. end if end five procedure six if click=1 then num2 +=6 put "6" .. end if if click=0 then click+=1 num1 +=6 put "6" .. end if end six procedure seven if click=1 then num2 +=7 put "7" .. end if if click=0 then click+=1 num1 +=7 put "7" .. end if end seven procedure eight if click=1 then num2 +=8 put "8" .. end if if click=0 then click+=1 num1 +=8 put "8" .. end if end eight procedure nine if click=1 then num2 +=9 put "9" .. end if if click=0 then click+=1 num1 +=9 put "9" .. end if end nine procedure minus op:= "-" put "-" .. end minus procedure plus op:= "+" put "+" .. end plus procedure times op:= "x" put "x" .. end times procedure divide op:= "/" put "/" .. end divide procedure equal if op="-" then answer:=num1-num2 elsif op="+" then answer:=num1+num2 elsif op="x" then answer:=num1*num2 elsif op="/" then answer:=num1/num2 end if put "=" .. put answer end equal procedure op="C" locate (1,1) put " " end clear var button1 : int := GUI.CreateButton (145, 25, 25, "-", minus) var button2 : int := GUI.CreateButton (25, 55, 25, "7", seven) var button3 : int := GUI.CreateButton (25, 85, 25, "4", four) var button4 : int := GUI.CreateButton (25, 115, 25, "1", one) var button5 : int := GUI.CreateButton (65, 25, 25, "C", clear) var button6 : int := GUI.CreateButton (65, 55, 25, "8", eight) var button7 : int := GUI.CreateButton (65, 85, 25, "5", five) var button8 : int := GUI.CreateButton (65, 115, 25, "2", two) var button9 : int := GUI.CreateButton (25, 25, 25, "0", zero) var button10 : int := GUI.CreateButton (105, 55, 25, "9", nine) var button11 : int := GUI.CreateButton (105, 25, 25, "=", equal) var button12 : int := GUI.CreateButton (105, 85, 25, "6", six) var button13 : int := GUI.CreateButton (105, 115, 25, "3", three) var button14 : int := GUI.CreateButton (145, 55, 25, "/", divide) var button15 : int := GUI.CreateButton (145, 85, 25, "+", plus) var button16 : int := GUI.CreateButton (145, 115, 25, "x", times) loop mousewhere (x, y, b) exit when b = 1 end loop loop exit when GUI.ProcessEvent end loop |
Author: | chrisbrown [ Fri May 11, 2007 8:18 pm ] |
Post subject: | RE:calculator using GUI |
You may want to do some error checking on this. I see [output] 12/3=0.142857 [/output] Looks like when the user punches in (for example) 12/3, the program calculates it as 3/21. Check your procedures' logic. Good start with GUI, though. |
Author: | DIIST [ Sat May 12, 2007 10:38 am ] |
Post subject: | Re: calculator using GUI |
1*2=12 This is almost like that time cube guy -1*-1=-1 . I agree there some thing wrong in you logic but good use of GUI. When you doing mathematical operations you might want to consider using a stack. |
Author: | gtahunter [ Sat May 12, 2007 11:50 am ] |
Post subject: | Re: calculator using GUI |
ya this might be the wrong one...but i checked it before i submitted it...i will fix it and re submit |
Author: | gtahunter [ Sat May 12, 2007 11:53 am ] |
Post subject: | Re: calculator using GUI |
in my description i ment to say you can only use single digits...no double triple and so on |