Urgent Help for Calculator Program
| Author |
Message |
Wajih
|
Posted: Mon Jan 17, 2011 7:02 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
| so would i have to do that for all the numbers? becuase i had to remake my calculator, it now only has 1 set of numbers |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
TokenHerbz

|
Posted: Mon Jan 17, 2011 8:56 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
number 1 (string form) += numbers (string) untill expression reached, then convert to int and move to number 2, repeat, when = then int expression int = answer. if ya get that...
I'm tempted to see if i can make a super overly complicated calculator for fun ofcourse, i'd have to make it really confusing tho so all you guys cant use it maybe ill get to it.. lol |
|
|
|
|
 |
Wajih
|
Posted: Mon Jan 17, 2011 9:08 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
so i have to make num and num2 strings then convert them to ints?
i am also having one more problem, since i had to remake my calculator, both sets of numbers have the same coordinates, num and num2. so say if i hit the number "9" both 9's show up, for num and num2. how do i make it so that if i hit nine, only the nine for num shows up, and not for the num2 until i hit the operator? |
|
|
|
|
 |
TokenHerbz

|
Posted: Mon Jan 17, 2011 9:43 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
well you just said it,
how do you know when num1 is done? when the operator is selected right... then you know to start number 2, then when do you calculate the answer, when the "=" is selected, make some if's or even if you have to, add some variables to keep track! |
|
|
|
|
 |
Wajih
|
Posted: Mon Jan 17, 2011 10:37 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
ok i get what you are saying but how do i make a code that when an operator is pressed, num stops, and num 2 begins?
do i have to make a new varaible or put in some loops? |
|
|
|
|
 |
Tony

|
Posted: Mon Jan 17, 2011 10:46 pm Post subject: Re: RE:Urgent Help for Calculator Program |
|
|
Wajih @ Mon Jan 17, 2011 10:37 pm wrote: do i have to make a new varaible or put in some loops?
Not necessarily, but if that helps you understand your code, then it could be helpful. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Wajih
|
Posted: Tue Jan 18, 2011 4:58 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
| hey token and tony, i crated a buttoncheck variable and it is boolean. if its false then it enters a number, and if its true it only enters an operator. but when its false it still enters an operator, any ideas why? |
|
|
|
|
 |
Tony

|
Posted: Tue Jan 18, 2011 5:13 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
Probably because you've implemented in a different way than what you are describing. Look closely.
Keep in mind that you wouldn't know that it's time to start entering an operator until an operator button has been pressed.
That is, if your current number so far is 42, you can't know if I'm going to press + (operator) or 1 (to enter 421) next. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Sponsor Sponsor

|
|
 |
Wajih
|
Posted: Tue Jan 18, 2011 7:06 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
or would i better off declaring buttoncheck as an integer?
i think it would be easier because it buttoncheck = 1 only num can be pressed. and after a number is pressed, the buttoncheck value is then 2, which allows to be an operator.
good?
bad? |
|
|
|
|
 |
TokenHerbz

|
Posted: Tue Jan 18, 2011 7:20 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
what you mean button check? something like this?? Are you using a class?
| Turing: |
fcn Click_Button (x_, y_ : int) : boolean
if x_ <= pos.x1 and x_ >= pos.x and y_ <= pos.y1 and y_ >= pos.y then
result true
end if
result false
end Click_Button
|
|
|
|
|
|
 |
Wajih
|
Posted: Tue Jan 18, 2011 7:28 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
whats a class?
how does it work?
buttoncheck is just a variable i created to mae sure when to hit an integer, or an operator |
|
|
|
|
 |
TokenHerbz

|
Posted: Tue Jan 18, 2011 7:29 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
oh yeah don't worry about class's yet.
hmm. not sure how yours works can you post it? |
|
|
|
|
 |
Wajih
|
Posted: Tue Jan 18, 2011 7:39 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
View.Set ("offscreenonly")
%Declaring the Variables
var num : int := 0
var num2 : int := 0
var answer : real := 0
var symbol : string := ""
var x, y, button : int := 0
var state : int := 0
var final : string := ""
var buttoncheck : int := 0
loop
drawbox (235, 100, 286, 135, black)
drawbox (340, 290, 400, 350, black)
drawbox (100, 100, 286, 475, black)
drawbox (100, 305, 286, 350, black)
drawbox (100, 100, 165, 135, 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 (140, 280, 10, 10, blue)
drawoval (180, 280, 10, 10, red)
drawoval (228, 280, 10, 10, green)
drawoval (260, 280, 10, 10, purple)
%Draws and locates the calculator and the numbers on the calculator
locate (3, 20)
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 (8, 33)
put "-" ..
locate (8, 18)
put "+" ..
locate (8, 29)
put "/" ..
locate (8, 23)
put "*" ..
locate (18, 33)
put "=" ..
locate (18, 15)
put "CLEAR" ..
%Looping the whole code
View.Update
if buttoncheck = 0 then
buttoncheck := buttoncheck + 1
locate (10, 50)
put buttoncheck
end if
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
%Gets value of first number
if (buttoncheck = 1) and (button = 1) and (x >= 196) and (x <= 215) and (y >= 110) and (y <= 130) then
locate (5, 14)
num := 0
put num ..
buttoncheck := 2
elsif (buttoncheck = 1) and (button = 1) and (x >= 137) and (x <= 158) and (y >= 142) and (y <= 163) then
locate (5, 14)
num := 1
buttoncheck := 2
put num ..
elsif (buttoncheck = 1) and (button = 1) and (x >= 194) and (x <= 214) and (y >= 142) and (y <= 163) then
locate (5, 14)
num := 2
put num ..
buttoncheck := 2
elsif (buttoncheck = 1) and (button = 1) and (x >= 251) and (x <= 272) and (y >= 142) and (y <= 163) then
locate (5, 14)
num := 3
put num ..
buttoncheck := 2
elsif (buttoncheck = 1) and (button = 1) and (x >= 137) and (x <= 158) and (y >= 190) and (y <= 208) then
locate (5, 14)
num := 4
put num ..
buttoncheck := 2
elsif (buttoncheck = 1) and (button = 1) and (x >= 194) and (x <= 214) and (y >= 190) and (y <= 208) then
locate (5, 14)
num := 5
put num ..
buttoncheck := 2
elsif (buttoncheck = 1) and (button = 1) and (x >= 251) and (x <= 272) and (y >= 190) and (y <= 208) then
locate (5, 14)
num := 6
put num ..
buttoncheck := 2
elsif (buttoncheck = 1) and (button = 1) and (x >= 137) and (x <= 158) and (y >= 241) and (y <= 258) then
locate (5, 14)
num := 7
put num ..
buttoncheck := 2
elsif (buttoncheck = 1) and (button = 1) and (x >= 196) and (x < 210) and (y > 237) and (y < 259) then
locate (5, 14)
num := 8
put num ..
buttoncheck := 2
elsif (buttoncheck = 1) and (button = 1) and (x >= 251) and (x <= 272) and (y >= 241) and (y <= 258) then
locate (5, 14)
num := 9
put num ..
buttoncheck := 2
end if
if buttoncheck = 1 then
buttoncheck := buttoncheck + 1
locate ( 20, 50)
put buttoncheck
end if
if buttoncheck = 2 then
if (button = 1) and (x >= 172) and (x <= 187) and (y >= 273) and (y <= 290) then
symbol := "*"
locate (5, 17)
put "*" ..
buttoncheck := 3
elsif (button = 1) and (x >= 220) and (x <= 236) and (y >= 273) and (y <= 290) then
symbol := "/"
locate (5, 17)
put "/" ..
buttoncheck := 3
elsif (button = 1) and (x >= 130) and (x <= 150) and (y >= 270) and (y <= 290) then
symbol := "+"
locate (5, 17)
put "+" ..
buttoncheck := 3
elsif (button = 1) and (x >= 240) and (x <= 270) and (y >= 270) and (y <= 290) then
symbol := "-"
locate (5, 17)
put "-" ..
buttoncheck := 3
end if
end if
if (button = 1) and (x >= 100) and (x <= 165) and (y >= 100) and (y <= 135) then
answer := 0
num := 0
num2 := 0
symbol := ""
cls
drawbox (235, 100, 286, 135, black)
drawbox (340, 290, 400, 350, black)
drawbox (100, 100, 286, 475, black)
drawbox (100, 305, 286, 350, black)
drawbox (100, 100, 165, 135, 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 (140, 280, 10, 10, blue)
drawoval (180, 280, 10, 10, red)
drawoval (228, 280, 10, 10, green)
drawoval (260, 280, 10, 10, purple)
locate (3, 20)
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 (8, 33)
put "-" ..
locate (8, 18)
put "+" ..
locate (8, 29)
put "/" ..
locate (8, 23)
put "*" ..
locate (18, 33)
put "=" ..
locate (18, 15)
put "CLEAR" ..
end if
%Gets value of second number
if buttoncheck = 2 then
buttoncheck := 3
end if
if buttoncheck = 3 and (num = 1) or (num = 2) or (num = 3) or (num = 4) or (num = 5) or (num = 6) or (num = 7) or (num = 8) or (num = 9) or (num = 0) then
if (button = 1) and (x >= 196) and (x <= 215) and (y >= 110) and (y <= 130) then
locate (5, 19)
num2 := 0
put num2 ..
end if
if (button = 1) and (x >= 137) and (x <= 158) and (y >= 142) and (y <= 163) then
locate (5, 19)
num2 := 1
put num2 ..
end if
if (button = 1) and (x >= 194) and (x <= 214) and (y >= 142) and (y <= 163) then
locate (5, 19)
num2 := 2
put num2 ..
end if
if (button = 1) and (x >= 251) and (x <= 272) and (y >= 142) and (y <= 163) then
locate (5, 19)
num2 := 3
put num2 ..
end if
if (button = 1) and (x >= 137) and (x <= 158) and (y >= 190) and (y <= 208) then
locate (5, 19)
num2 := 4
put num2 ..
end if
if (button = 1) and (x >= 194) and (x <= 214) and (y >= 190) and (y <= 208) then
locate (5, 19)
num2 := 5
put num2 ..
end if
if (button = 1) and (x >= 251) and (x <= 272) and (y >= 190) and (y <= 208) then
locate (5, 19)
num2 := 6
put num2 ..
end if
if (button = 1) and (x >= 137) and (x <= 158) and (y >= 241) and (y <= 258) then
locate (5, 19)
num2 := 7
put num2 ..
end if
if (button = 1) and (x >= 196) and (x < 210) and (y > 237) and (y < 259) then
locate (5, 19)
num2 := 8
put num2 ..
end if
if (button = 1) and (x >= 251) and (x <= 272) and (y >= 241) and (y <= 258) then
locate (5, 19)
num2 := 9
put num2 ..
end if
end if
if (button = 1) and (x >= 172) and (x <= 187) and (y >= 273) and (y <= 290) then
symbol := "*"
locate (5, 17)
put "*" ..
end if
if (button = 1) and (x >= 172) and (x <= 187) and (y >= 273) and (y <= 290) then
symbol := "*"
locate (5, 17)
put "*" ..
end if
if (button = 1) and (x >= 220) and (x <= 236) and (y >= 273) and (y <= 290) then
symbol := "/"
locate (5, 17)
put "/" ..
end if
if (button = 1) and (x >= 323) and (x <= 341) and (y >= 271) and (y <= 290) then
symbol := "+"
locate (5, 17)
put "+" ..
end if
if (button = 1) and (x >= 240) and (x <= 240) and (y >= 270) and (y <= 290) then
symbol := "-"
locate (5, 17)
put "-" ..
end if
%Process the two numbers and decides to add, multiply, divide, or subtract them
if symbol = "*" and final = "=" then
answer := num * num2
locate (5, 46)
put answer ..
elsif symbol = "/" and final = "=" then
answer := num / num2
locate (5, 46)
put answer ..
elsif symbol = "+" and final = "=" then
answer := num + num2
locate (5, 46)
put answer ..
elsif symbol = "-" and final = "=" then
answer := num - num2
locate (5, 46)
put answer ..
end if
if (button = 1) and (x >= 235) and (x <= 286) and (y >= 100) and (y <= 135) then
final := "="
end if
locate (1, 1)
put "Welcome to" ..
locate (2, 1)
put "Wajihs Basic" ..
locate (3, 1)
put "Calculator" ..
end loop
% End of program
i had to post all of it because i am having a problem. num wont display,
can you test it out and tell me what is the problem? |
|
|
|
|
 |
Wajih
|
Posted: Tue Jan 18, 2011 8:36 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
| plz help its due on friday |
|
|
|
|
 |
Tony

|
Posted: Tue Jan 18, 2011 8:41 pm Post subject: RE:Urgent Help for Calculator Program |
|
|
That's _plenty_ of time. Though considering that you still have things like
I can tell that you are not really following up on any advice given out so far. I think your best bet right now is to schedule some time with your teacher to go over your program in person. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
|
|