Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Please Help...My first program.

Author
Message
Ragnarok89
20
Years of Service
User Offline
Joined: 27th Jun 2004
Location: Look behind you! Ahhhh!~
Posted: 13th Jul 2004 12:23
start:
print "What would you like to do?"
print "(1) Add two numbers"
print "(2) Subtract two numbers"
print "(3) Multiply two numbers"
print "(4) Divide two numbers"
input a
cls
if a=1 then gosub add
if a=2 then gosub sub
if a=3 then gosub mul
if a=4 then gosub div
add:
print "What is the first number?"
input b
print "What is the second number?"
input c
print "The answer is"
print b+c
goto start
sub:
print "What is the first number?"
input b
print "What is the second number?"
input c
print "The answer is"
print b-c
goto start
mul:
print "What is the first number?"
input b
print "What is the second number?"
input c
print "The answer is"
print b*c
goto start
div:
print "What is the first number?"
input b
print "What is the second number?"
input c
print "The answer is"
print b/c
goto start


I wrote this simple calculator as my first program...but for some when it adds,subtracts, etc...i won't print a decimal, only a whole number. Can anyone figure out why this is happening please?

Thanks in advance.
Rich
Ocean Runner
21
Years of Service
User Offline
Joined: 18th May 2003
Location: United States
Posted: 13th Jul 2004 12:58
Simple. You just need to put a # symbol after every one of your variables. That will turn it into a float, which can have decimals.

Also, you shouldn't use goto. Instead, replace start: with do, and goto start with loop. That will make it have a do loop, which can be exited out of and is in general better programming technique.

When it hits the loop, it goes back to the do.

"Computers in the future may weigh no more then
1.5 tons. - Popular Mechanics, 1949
Ocean Runner
21
Years of Service
User Offline
Joined: 18th May 2003
Location: United States
Posted: 13th Jul 2004 13:00
Also, what you can do is make a subroutine named input, and in that subroutine have this:

That way you can just do a gosub input at the beginning of each of the other subroutines, and save typing, as well as making it easier for future modification. Try to do this whenever you have the same bit of code repeating a few times.

"Computers in the future may weigh no more then
1.5 tons. - Popular Mechanics, 1949
Ragnarok89
20
Years of Service
User Offline
Joined: 27th Jun 2004
Location: Look behind you! Ahhhh!~
Posted: 13th Jul 2004 13:43
Thanks Ocean Runner.

Login to post a reply

Server time is: 2024-09-22 16:31:39
Your offset time is: 2024-09-22 16:31:39