Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Help Gui. Calculator
Author Message
Evilkilla

Posted: Sat May 29, 2004 1:31 pm   Post subject: Help Gui. Calculator

Hey guys i need some help
ok i am trying to make a calculator with GUI using functions and strreal
i am trying to find out how, too...... use the = button to output, as in say i use my variable adder to hold the strings while i use strreal and put it in num1 somehow using a if statement or...... i am not sure, any pointers would be nice thanks. to output say 1 + 1 = 2 thanks
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

guruguru

Posted: Sat May 29, 2004 3:43 pm   Post subject: (No subject)

You have to make 'adder' a integer, nd then when a button is clicked, you add that button's number value to 'adder'. When you press equal, you display adder.

Then you have to include divide and such. In your button procedures, you should if statements to see if divide or whatever has been pressed, and then change adder accordingly by the next number pressed.
Evilkilla

Posted: Sat May 29, 2004 3:58 pm   Post subject: (No subject)

huh.... but i have to use Adder with is a string to store the buttons pressed and the numbers and then convert it with strreal to a real number.. i am stuck at there... i dunno what to do next help plz thanks
like below to store the numbers pressed.
guruguru

Posted: Sat May 29, 2004 6:33 pm   Post subject: (No subject)

But thats my point... you should make adder an integer. Its easier to do everything. You can do all calculations at any point in the program, not just at the end where you convert it.
Evilkilla

Posted: Sat May 29, 2004 6:59 pm   Post subject: (No subject)

could you gimme an example i dun understand
guruguru

Posted: Sat May 29, 2004 7:08 pm   Post subject: (No subject)

 code: var num1 : int var num2 : int var currentNum : int proc b4     put "4 " ..     if currentNum := 1 then         num1 := 4     elsif currentNum := 2 then         num2 := 4     end if     currentPress += 1    end b1 proc b2     put "2 " ..     if currentNum := 1 then         num1 := 2     elsif currentNum := 2 then         num2 := 2     end if     currentPress += 1    end b1 proc b10     put "/ ", num1 / num2 end b10 proc b12     put "+ ", num1 + num2 end b12 % All your button stuff here
Evilkilla

Posted: Sat May 29, 2004 7:51 pm   Post subject: (No subject)

i tried, it says must be boolean type
p.s your end procedures are wrong end b1 for b4
guruguru

Posted: Sat May 29, 2004 9:28 pm   Post subject: (No subject)

Sorry, the error is my mistake. In the if statements, any that say ":=" replace with "=".

Quote:
p.s your end procedures are wrong end b1 for b4

I cannot for the life of me understand what you just said.

Evilkilla

Posted: Sat May 29, 2004 10:02 pm   Post subject: (No subject)

ahhh sorry

Quote:
proc b4
put "4 " ..
if currentNum := 1 then
num1 := 4
elsif currentNum := 2 then
num2 := 4
end if
currentPress += 1
end b1

proc b2
put "2 " ..
if currentNum := 1 then
num1 := 2
elsif currentNum := 2 then
num2 := 2
end if
currentPress += 1
end b1

see procedure b2, end is b1
same with b4
Evilkilla

Posted: Sat May 29, 2004 10:09 pm   Post subject: (No subject)

also Currentnum and CurrentPress is not declared what should it be... and what is it used for.............program doesn't run,
guruguru

Posted: Sat May 29, 2004 10:22 pm   Post subject: (No subject)

I made a slight modification so it works. I made a operation variable that tells what operation to perform. Kinda self-explanitory. If you have questions please ask.

 code: import GUI var num1 : int var num2 : int var currentNum : int := 1 var operation : string proc b4     put "4 " ..     if currentNum = 1 then         num1 := 4     elsif currentNum = 2 then         num2 := 4     end if     currentNum += 1 end b4 proc b2     put "2 " ..     if currentNum = 1 then         num1 := 2     elsif currentNum = 2 then         num2 := 2     end if     currentNum += 1 end b2 proc b10     operation := "divide"     put "/ " .. end b10 proc b12     operation := "add"     put "+ " .. end b12 proc b15     put "= " ..     if operation = "add" then         put num1 + num2     elsif operation = "divide" then         put num1 / num2     end if end b15 var button2 : int := GUI.CreateButton (80, 100, 60, "2", b2) var button4 : int := GUI.CreateButton (10, 70, 60, "4", b4) var button10 : int := GUI.CreateButton (220, 100, 60, "/", b10) var button12 : int := GUI.CreateButton (220, 40, 60, "+", b12) var button15 : int := GUI.CreateButton (150, 10, 60, "=", b15) loop     % loop should start here and not above     exit when GUI.ProcessEvent end loop

PS: You can add in rest of buttons and procs.
Evilkilla

Posted: Sat May 29, 2004 11:29 pm   Post subject: (No subject)

Thanks man you helped me out alot!, i will post finished product for you guys when i am done and with you for credit!!
guruguru

Posted: Sun May 30, 2004 12:05 am   Post subject: (No subject)

Sweet ! I wanna see the finished product 8) .
Evilkilla

Posted: Wed Jun 02, 2004 8:29 pm   Post subject: (No subject)

ahhhh i need help again, each person who helps with legit info gets 5 bits from me, first come first serve. Guru imma give you 5. So first 2 gets the other bits. Well heres the problem now.. I can't use more than one operator. and numbers.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 14 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: