Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Calculator Questions
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2, 3, 4  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tony




PostPosted: Fri Jan 14, 2011 12:03 am   Post subject: RE:Calculator Questions

You could post the relevant parts here.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Wajih




PostPosted: Fri Jan 14, 2011 8:55 pm   Post subject: RE:Calculator Questions

var num : real := 0
var num2 : real := 0

var symbol : string := ""
var x, y, button : int := 0
var state : string := ""


put "what state would you like to work in? ( 0 ) Right now this calculator does not do double digit operations. but it will be able to soon "

get state
cls


if (state not= "0") then
put "I am sorry but you have entered an invalid number. Please try again."
put ""
end if

View.Set ("offscreenonly")
if state = "0" then
loop

View.Update

Mouse.Where (x, y, button)
Text.Locate (24, 1)
if button = 0 then
put x : 0, " ", y : 0, " button up"
else
put x : 0, " ", y : 0, " button down"
end if


if (button = 1) and (x >= 196) and (x <= 215) and (y >= 110) and (y <= 130) then
locate (5, 19)
num := 0
put num ..

end if

if (button = 1) and (x >= 137) and (x <= 158) and (y >= 142) and (y <= 163) then
locate (5, 19)
num := 1
put num ..
end if

if (button = 1) and (x >= 194) and (x <= 214) and (y >= 142) and (y <= 163) then
locate (5, 19)
num := 2
put num ..
end if

if (button = 1) and (x >= 251) and (x <= 272) and (y >= 142) and (y <= 163) then
locate (5, 19)
num := 3
put num ..
end if

if (button = 1) and (x >= 137) and (x <= 158) and (y >= 190) and (y <= 208) then
locate (5, 19)
num := 4
put num ..
end if

if (button = 1) and (x >= 194) and (x <= 214) and (y >= 190) and (y <= 208) then
locate (5, 19)
num := 5
put num ..
end if

if (button = 1) and (x >= 251) and (x <= 272) and (y >= 190) and (y <= 208) then
locate (5, 19)
num := 6
put num ..
end if

if (button = 1) and (x >= 137) and (x <= 158) and (y >= 241) and (y <= 258) then
locate (5, 19)
num := 7
put num ..
end if

if (button = 1) and (x >= 196) and (x < 210) and (y > 237) and (y < 259) then
locate (5, 19)
num := 8
put num ..
end if


if (button = 1) and (x >= 251) and (x <= 272) and (y >= 241) and (y <= 258) then
locate (5, 19)
num := 9
put num ..
end if




drawbox (100, 100, 500, 475, red)
drawbox (128, 305, 470, 350, black)

locate (2, 32)
put "CALCULATOR" ..
locate (18, 26)
put "0" ..
locate (16, 19)
put "1" ..
locate (16, 26)
put "2" ..
locate (16, 33)
put "3" ..
locate (13, 19)
put "4" ..
locate (13, 26)
put "5" ..
locate (13, 33)
put "6" ..
locate (10, 19)
put "7" ..
locate (10, 26)
put "8" ..
locate (10, 33)
put "9" ..
locate (5, 43)
put "=" ..
locate (8, 48)
put "-" ..
locate (8, 42)
put "+" ..
locate (8, 29)
put "/" ..
locate (8, 23)
put "*" ..
locate (13, 57)
put "0" ..
locate (16, 40)
put "1" ..
locate (16, 45)
put "2" ..
locate (16, 50)
put "3" ..
locate (13, 40)
put "4" ..
locate (13, 45)
put "5" ..
locate (13, 50)
put "6" ..
locate (10, 40)
put "7" ..
locate (10, 45)
put "8" ..
locate (10, 50)
put "9" ..
locate (16, 55)
put "CLEAR" ..

drawbox (426, 137, 479, 164, black)
drawoval (452, 200, 15, 15, black)
drawoval (205, 120, 12, 12, black)
drawoval (148, 151, 12, 12, black)
drawoval (205, 151, 12, 12, black)
drawoval (262, 151, 12, 12, black)
drawoval (148, 200, 12, 12, black)
drawoval (205, 200, 12, 12, black)
drawoval (262, 200, 12, 12, black)
drawoval (148, 249, 12, 12, black)
drawoval (205, 249, 12, 12, black)
drawoval (262, 249, 12, 12, black)
drawoval (316, 200, 13, 13, black)
drawoval (316, 151, 13, 13, black)
drawoval (356, 200, 13, 13, black)
drawoval (396, 200, 13, 13, black)
drawoval (396, 152, 13, 13, black)
drawoval (356, 152, 13, 13, black)
drawoval (316, 248, 13, 13, black)
drawoval (356, 248, 13, 13, black)
drawoval (396, 248, 13, 13, black)
drawoval (180, 280, 10, 10, black)
drawoval (228, 280, 10, 10, black)
drawoval (332, 279, 12, 12, black)
drawoval (380, 279, 12, 12, black)
drawfillbox (285, 100, 286, 300, black)





if (button = 1) and (x >= 440) and (x <= 465) and (y >= 187) and (y <= 213) then
locate (5, 25)
num2 := 0
put num2 ..
end if



if (button = 1) and (x >= 305) and (x <= 327) and (y >= 140) and (y <= 163) then
locate (5, 25)
num2 := 1
put num2 ..
end if

if (button = 1) and (x >= 345) and (x <= 367) and (y >= 140) and (y <= 163) then
locate (5, 25)
num2 := 2
put num2 ..
end if

if (button = 1) and (x >= 386) and (x <= 406) and (y >= 140) and (y <= 163) then
locate (5, 25)
num2 := 3
put num2 ..
end if

if (button = 1) and (x >= 305) and (x <= 327) and (y >= 190) and (y <= 211) then
locate (5, 25)
num2 := 4
put num2 ..
end if

if (button = 1) and (x >= 345) and (x <= 367) and (y >= 190) and (y <= 211) then
locate (5, 25)
num2 := 5
put num2 ..
end if

if (button = 1) and (x >= 386) and (x <= 406) and (y >= 190) and (y <= 211) then
locate (5, 25)
num2 := 6
put num2 ..
end if

if (button = 1) and (x >= 305) and (x <= 327) and (y >= 238) and (y <= 260) then
locate (5, 25)
num2 := 7
put num2 ..
end if

if (button = 1) and (x >= 345) and (x <= 367) and (y >= 238) and (y <= 260) then
locate (5, 25)
num2 := 8
put num2 ..
end if

if (button = 1) and (x >= 386) and (x <= 406) and (y >= 238) and (y <= 260) then
locate (5, 25)
num2 := 9
put num2 ..
end if


if (button = 1) and (x >= 172) and (x <= 187) and (y >= 273) and (y <= 290) then
locate (5, 22)
put "*" ..
locate (5, 45)
put num * num2 ..

end if

if (button = 1) and (x >= 220) and (x <= 236) and (y >= 273) and (y <= 290) then
locate (5, 22)
put "/" ..
locate (5, 45)
put num / num2 ..
end if

if (button = 1) and (x >= 323) and (x <= 341) and (y >= 271) and (y <= 290) then
locate (5, 22)
put "+" ..
locate (5, 45)
put num + num2 ..
end if

if (button = 1) and (x >= 370) and (x <= 389) and (y >= 271) and (y <= 290) then
locate (5, 22)
put "-" ..
locate (5, 45)
put num - num2 ..
end if

if (button = 1) and (x >= 426) and (x <= 479) and (y >= 137) and (y <= 164) then
cls
end if

locate (20, 1)
put
"INSTRUCTIONS : to get your desired answer, you must first enter a number on the left side of the calculator, and then enter a number on the right side. Once youhave done that enter an operator"
locate (1, 1)
put "Welcome to" ..
locate (2, 1)
put "Wajihs Basic" ..
locate (3, 1)
put "Calculator" ..

end loop
end if


im sorry, i had to post of all it because im confused. i tried making num and num 2 string with a value of "" but even that did not work. that is the reason i posted all of my code
Wajih




PostPosted: Fri Jan 14, 2011 10:34 pm   Post subject: RE:Calculator Questions

i was reading something about arrays. can i do something like that for this program?
TokenHerbz




PostPosted: Fri Jan 14, 2011 10:44 pm   Post subject: RE:Calculator Questions

YES OMG, how about an array of a class of these buttons? --> Lets fix this yes yes?
Wajih




PostPosted: Fri Jan 14, 2011 11:22 pm   Post subject: RE:Calculator Questions

im not sure if you're being serious or not lol, no offense, but would arrays work in this case?
Tony




PostPosted: Fri Jan 14, 2011 11:33 pm   Post subject: RE:Calculator Questions

I am assuming the the coordinates of any particular button can be figured out based on its index, so maybe just a for-loop instead?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Wajih




PostPosted: Sat Jan 15, 2011 12:02 am   Post subject: RE:Calculator Questions

wouldnt you have to make up a nex variable then?

cant just do like this:

for i : 0 ...1000000
end for

or something like that
Wajih




PostPosted: Sat Jan 15, 2011 4:41 pm   Post subject: RE:Calculator Questions

hold up. my two sets of numbers are in the same loop. do i have to make num in one loop and num2 in another, then loop them ?

right now it is like this:

loop
num
num2
end loop

but should it be like this? :

loop
loop
num
end loop
loop
num2
end loop
end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Jan 15, 2011 7:23 pm   Post subject: RE:Calculator Questions

In the second version, you'd be looping as you are entering the first number, end when you are done, then loop while entering the second number.

That sounds like a right thing to do.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Wajih




PostPosted: Sat Jan 15, 2011 8:42 pm   Post subject: RE:Calculator Questions

the second state? or the second version of the loop that i posted?
Tony




PostPosted: Sat Jan 15, 2011 8:45 pm   Post subject: RE:Calculator Questions

The second version of the loop. You'd need to keep track of your states to figure out when to exit one loop and enter into another.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Wajih




PostPosted: Sat Jan 15, 2011 9:26 pm   Post subject: RE:Calculator Questions

alright but how many view updates would you have and where wouldyou put them in the loops?
Tony




PostPosted: Sat Jan 15, 2011 9:30 pm   Post subject: RE:Calculator Questions

Think about what View.Update does, that should lead towards the answer (or to the question that should lead towards the answer Wink). There are also examples in documentation -- View.Update
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Wajih




PostPosted: Sat Jan 15, 2011 9:46 pm   Post subject: RE:Calculator Questions

so there should be 3?

because there are 3 loops and each loop is drawing the calculator?
Tony




PostPosted: Sat Jan 15, 2011 9:50 pm   Post subject: RE:Calculator Questions

That sounds correct.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 4  [ 55 Posts ]
Goto page Previous  1, 2, 3, 4  Next
Jump to:   


Style:  
Search: