Obviously locking the thread was only a joke - hence the smiley.
But, there was a serious point to my post - it's not a good idea bumping threads to keep them at the top if they aren't worthy.
Newcomers will see code in posts and mistakenly assume that's the way programs should be written.
There are a lot of coders on the forums that have been doing so for many, many years (me personally for nearly 30 years) and they tend to know what they are talking about.
Whenever they offer advice and point out where you have gone wrong is not to take the mickey or make fun of you - it's because we want you to improve.
It's annoying though when your good advice is repeatedly ignored and you tend not to help that person again...
I mentioned indentation. What you did isn't indentation - it's called making pretty patterns!
Download my program DBA Tidy from the Program Announcements board and run your programs through it.
http://forum.thegamecreators.com/?m=forum_view&t=104344&b=5&p=0
Here's your second snippet indented correctly:
Set display mode 1024,768,32
rem intro text
Print "Hello, welcome to calculator 2.0"
Print "This calculator ONLY preforms these functions, +,-,*,/,^and Sqrt()."
Input "Start?<y/n>",go$
rem main user in input, two numbers and your operator
if go$= "y"
Cls
_start_:
Print "Now select numbers and operators."
Input "First Number?",No1#
Input "Operator?",Op$
rem if statements for operations
If op$ ="+"
input "Second number?",No2#
print no1#+no2#
Wait key
cls
goto _start_
endif
if op$ = "-"
input "Second number?",No2#
print no1#-No2#
Wait key
cls
goto _start_
endif
if op$ = "*"
input "Second number?",No2#
print no1#*no2#
Wait key
cls
goto _start_
endif
if op$ = "/"
input "Second number?",No2#
print no1#/no2#
Wait key
cls
goto _start_
endif
if op$ = "^"
input "Second number?",No2#
print no1#^no2#
Wait key
cls
goto _start_
endif
If op$ = "sqrt()"
Print Sqrt(no1#)
Wait key
Cls
Goto _start_
endif
else
wait 2000
Cls
goto _start_
endif
end
First of all, properly indented code starts at the left edge of the screen at the beginning of your program and should finish at the left edge at the end of your program. If it doesn't, then you have a problem.
Guess what... you have a problem!
Indented, you can instantly see that your code has a missing Endif to go with the 'if go$= "y"' line. With your unique indenting scheme it would have taken a bit longer - imagine doing the same with a program 10,000 lines long!
We know you're new to programming and we also know that it's the best time to knock bad habits out of you and try to impress how important things like program layout are. Yes it's boring, but essential if you want to write easily maintainable code.
Goto is a bad habit and in my book it shouldn't be used unless there is absolutely no other available option. So far I've not seen an example which could not have been written in any other way.
So, Phaelax suggested you try to write it again with functions instead of gosub - which I think was a typo and he meant to say instead of Goto.
Your second version
still uses Goto. You need to make it 'modular'.
Quote: "And what would you use besides GOTO"
If you don't know how to do that then you
still haven't read the tutorials I pointed you to. Like I said, ignore good advice and you'll eventually not get any advice at all...
So, I've re-written your code in a modular fashion. There are literally lots of good reasons to do it - and none not to do it!
1. Notice how much cleaner and easier to read it is.
2. It doesn't have a single Goto anywhere.
3. Adding new functions is a doddle.
4. With a module dedicated to each task, finding bugs is much easier.
5. It's quicker to write. Your re-write took six minutes!
Adding new functions to the calculator is a simple case of dropping another procedure in and adding a Gosub.
So, finally, here it is:
Set display mode 1024,768,32
rem intro text
Print "Hello, welcome to calculator 2.0"
Print "This calculator ONLY preforms these functions, +,-,*,/,^and Sqrt()."
Print "To exit, don't type anything - just press Enter"
Do
Gosub DataInput
Gosub DataProcess
Loop
DataInput:
Cls
Print "'+' Add '-' Subtract '*' Multiply '/' Divide '^' Power Of 'Sqr' Square 'Sqrt' Square Root"
Print
Print "Now select numbers and operators."
Input "First Number: ",No1#
Input "Operator: ",Op$
Op$ = Upper$(Op$)
Return
DataProcess:
Select Op$
Case "+"
Gosub Addition
EndCase
Case "-"
Gosub Subtraction
EndCase
Case "*"
Gosub Multiplication
EndCase
Case "/"
Gosub Division
EndCase
Case "^"
Gosub PowerOf
EndCase
Case "SQR"
Gosub Square
EndCase
Case "SQRT"
Gosub SquareRoot
EndCase
Case ""
End
EndCase
Case Default
Print "Sorry - That operator is not recognised..."
Wait Key
EndCase
EndSelect
Return
Addition:
input "Second number: ",No2#
print
print "Answer: ";no1#+no2#
Wait key
Return
Subtraction:
input "Second number: ",No2#
print
print "Answer: ";no1#-no2#
Wait key
Return
Multiplication:
input "Second number: ",No2#
print
print "Answer: ";no1#*no2#
Wait key
Return
Division:
input "Second number: ",No2#
print
print "Answer: ";no1#/no2#
Wait key
Return
PowerOf:
input "Second number: ",No2#
print
print "Answer: ";no1#^no2#
Wait key
Return
Square:
print
print "Answer: ";no1#*no1#
Wait key
Return
SquareRoot:
print
print "Answer: ";Sqrt(no1#)
Wait key
Return
Don't you think that's easier to follow and add to? And it runs too!
TDK_Man