freebasic - Free Basic Calculator Issue -
i have attempted create calculator freebasic. problem line 9
in code? line 6
says dim choice default , not allowed while line 9
tells me variable isn't declared.
1 declare sub main 2 declare sub add 3 declare sub subtract 4 main 5 sub main 6 dim choice 7 print "1.add" 8 print "2.subtract" 9 input "what choice" ; choice
your source code quite incomplete. example, misses data types. in freebasic choose between several data types depending on kind of data want store (integer, double, string, ...). moreover, did not define how sub programs should work. didn't give code procedure "subtract" should do.
here's working example of small calculator:
' these 2 functions take 2 integers (..., -1, 0, 1, 2, ...) , ' return 1 integer result. ' here find procedure declarations ("what inputs , outputs ' exist?"). implementation ("how these procedures ' work?") follows @ end of program. declare function add (a integer, b integer) integer declare function subtract (a integer, b integer) integer ' == begin of main program == dim choice integer print "1. add" print "2. subtract" input "what choice? ", choice ' use "input" (see choice above) values user. dim integer x, y x = 10 y = 6 if (choice = 1) print add(x, y) elseif (choice = 2) print subtract(x, y) else print "invalid input!" end if print "press key quit." getkey end ' == end of main program == ' == sub programs (procedures = subs , functions) here on == function add (a integer, b integer) integer return + b end function function subtract (a integer, b integer) integer return - b end function
Comments
Post a Comment