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 / This probably has been done a million times, but...

Author
Message
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 10th May 2007 03:22 Edited at: 12th May 2007 05:39
Just a simple calculator, non-compressed, but VERY basic, only adds, subtacts, muptiplies, and divides.


Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
Gil Galvanti
19
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 10th May 2007 03:42
well it's good to know your not trying to start with an MMORPG like most newcomers . Nice simple beginning program .


n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 10th May 2007 03:54
Thnx.

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 10th May 2007 03:55
But it has the wrong remarks, lol, that was 4 a random number generator.

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th May 2007 05:08
Now try to make the same program using functions instead of gosub. Use a loop to return to the beginning. Here's a tip also, indent your code. Makes it much more readable.


n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 10th May 2007 05:26
Thnx 4 teh tips.

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 11th May 2007 05:37
Gota keep dis alive!

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 11th May 2007 05:47
Quote: "Gota keep dis alive"


Why?

Wouldn't it be better to do so by following the advice of those who have posted - rather than just bumping it for no apparent reason?

Why not post a useful version that other newcomers can learn from - for example, written properly without using Goto and with indentation?

Or put a way you might understand:

Dis is a naff thred - I tink I gona lok it!

TDK_Man

n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 12th May 2007 00:38 Edited at: 12th May 2007 00:39
Quote: "Or put a way you might understand:

Dis is a naff thred - I tink I gona lok it!

TDK_Man
"

WTF? This calculator can raise to powers

, but how would you do sqaure roots? And what would you use besides GOTO, and what is wrong with that?

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 12th May 2007 00:48
Goto can make a program really messy. You'll probably understand further once you learn about functions etc.

As for square roots, either use the sqrt() function, or do raise to the power of 0.5.

I made a maths parser once. It could solve things such as 3+4-(6*(4/3)). My latest also can call functions made by the user (this is for my scripting language). So it can do things like 9-sqrt(16).

It's not that hard, the algorithms make perfect sense, but it gets a little tricky to program, especially in DBPro. C++ FTW!

n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 12th May 2007 01:12
thanks, as u can tell, im VERY new.

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 12th May 2007 01:13
Yeah, but it's good to see that you automatically went to make simple things where you get to learn at a reasonable rate, and didn't fall for the usual MMORPG trap.

n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 12th May 2007 01:28

Ok, i modified it for sqrt(), what do you think?

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 12th May 2007 01:29
Quote: "Yeah, but it's good to see that you automatically went to make simple things where you get to learn at a reasonable rate, and didn't fall for the usual MMORPG trap."

My first program was just a thing that generated whatever you typed in all over the screen, then stopped and started again.

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
Bartman
19
Years of Service
User Offline
Joined: 26th May 2005
Location: A rural village in NSW Australia.
Posted: 12th May 2007 02:38 Edited at: 12th May 2007 02:39
Quote: "Wouldn't it be better to do so by following the advice of those who have posted - rather than just bumping it for no apparent reason?
Why not post a useful version that other newcomers can learn from - for example, written properly without using Goto and with indentation?
Or put a way you might understand:
Dis is a naff thred - I tink I gona lok it!
TDK_Man"


I-do-kind-of-agree.
Also, a better place for this type of discussion would be the DBPro newcomers Corner. Rather than chocking up this end of town with noobie nerdz' naff nonsense!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th May 2007 03:00 Edited at: 12th May 2007 03:05
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:



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:



Don't you think that's easier to follow and add to? And it runs too!

TDK_Man

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th May 2007 03:07
Quote: "Also, a better place for this type of discussion would be the DBPro newcomers Corner"


Very good point which I should have spotted earlier - moving it now.

TDK_Man

n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 12th May 2007 05:39
After three minutes of analysis of the gosub-written code... I get your point.

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!

Login to post a reply

Server time is: 2024-09-26 22:54:46
Your offset time is: 2024-09-26 22:54:46