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 / Basic Maths

Author
Message
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 29th Jan 2006 15:22
Hi I can't seem to figure out how the maths work in this simple for and next loop. I'm trying to number, the random numbers generated in the array, from 1 to 40. I'm have tried everything I can think of but to no avail, are there any good links, that could teach me or can anyone talk me through the fundamental basics of how a computer will output what I want it to.
I do feel a bit stupid asking this simple question, but I'm beginning to realize now that programming involves a lot of maths, which unfortunatley is not one of my strongest points!

Thanks Ant !

Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 29th Jan 2006 15:28
At your print line, try this instead.


Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 29th Jan 2006 18:12
Hey thanks for post, unfortunatley it doesn't work, or at least it didn't work on my version of Darkbasic Pro V5.9
What version are you running Image, and does it work on your's?
harggood
21
Years of Service
User Offline
Joined: 9th Apr 2003
Location: the forest
Posted: 29th Jan 2006 18:44 Edited at: 29th Jan 2006 18:48
Quote: "num=(1*y)"


num = x*y

Quote: "print num,"= ",ages(x,y)"


text$=str$(num) + " = " + str$(ages(x,y))
print text$

Maybe

Awfuldark Forest
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 29th Jan 2006 19:51
mmmmh well I'm glad I'm not the only one who is having a problem, good ideas guys, but so far none work,just to be a bit clearer on what I want it to do

[/code]
1 11 21 31
2 12 22 32
3 13 23 33
4 14 24 34
5 15 25 35
6 16 26 36
7 17 27 37
8 18 28 38
9 19 29 39
10 20 30 40
[code]

numbered like so with corresponding array, I really do want to figure this one out, hope you can help, and like I said earlier if anyone can point me in the right direction, to some good examples of basic math problem solving for programming or could explain the basics I would really appreciate it

Thank you.
Don Malone
21
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 29th Jan 2006 20:18 Edited at: 29th Jan 2006 20:28
Is that the output you want?

if so this code gives you that. It properly number your randoms. This is the line of importance

num=(y+(10*(x-1)))



[edited for clarity. Not that it helped.]

In Memory of My Dad.
I miss you very much.
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 29th Jan 2006 20:38
Hey thanks DBoy

I messed around with your equation, to print the numbers horizontally as follows.



Thanks for your help, now if someone could tell me of a good website or link to learn basic math equations for programming I'd be set, Thanks for all your help guys, probably annoy you soon with some more !!!!!!!!!!
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 29th Jan 2006 20:51
although I tried to adjust your equation to do it horizontally its not assigning the right variable with the random array, I've got a feeling if you wanted to do that, it would get a lot more complicated, any suggestions?

Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 29th Jan 2006 21:25
Just realized I would have to call it print ages(3,4) because the array has not changed the way it stores the random numbers
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 29th Jan 2006 22:08
Quote: "1 11 21 31
2 12 22 32
3 13 23 33
4 14 24 34
5 15 25 35
6 16 26 36
7 17 27 37
8 18 28 38
9 19 29 39
10 20 30 40"


I may be missing the boat but if that's the output you want why do you get random numbers?




Don Malone
21
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 30th Jan 2006 03:39 Edited at: 30th Jan 2006 12:45
what he is doing is counting the random numbers. the actual out put is more like

Quote: "
1-## 11-## 21-## 31-##
2-## 12-## 22-## 41-##

etc...
where ## = the random number.


@ant
the trick is not the line you adjusted
num=(x+(4*y)-4)
but the line you are using to print the results
set cursor y*150,x*20

by swapping the x and y you change the output. the question is how flexable does it have to be. If you want a flexable printout, the code will have to get much more complicated, I think, using more variables.
"


[edit] - code follows


In Memory of My Dad.
I miss you very much.
Don Malone
21
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 30th Jan 2006 03:43 Edited at: 30th Jan 2006 12:44
If you want more flexability in printout. You would be better served just using a straight array with say 40 elements and fill that with random numbers. Then you can control the printing much easier by placing the cursor and printing and then relocating the cursor with a simple mathmatical formula.

If you are trying to make the previous code more flexable, then you are headed for a coding headache.

In Memory of My Dad.
I miss you very much.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 30th Jan 2006 05:36
Yeah a one dimensional array would be better. Also using the "text" command combines both "set cursor" and the "print" commands.




Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 30th Jan 2006 23:24
Thanks for all your advice guys, I'll have a play around with all the code you have, all generously suggested and see which one works out best.

Ant !!!!!!!!!

Login to post a reply

Server time is: 2024-09-24 15:30:08
Your offset time is: 2024-09-24 15:30:08