Qbasicnews.com
April 08, 2020, 10:55:51 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: Help Me And I Will Become Your Slave  (Read 7070 times)
Janesh
Member
*
Posts: 64


« Reply #15 on: September 07, 2003, 02:52:14 AM »

hmm ok i see what you want..


i thought over it a bit and realised that id have to make a table like so:

   A B C D
A X 8 3 2
B 2 X 3 1
C 5 2 X 7
D 4 3 8 X

where ABCD are the cities and the numbers are the fares

i have the fares written on a piece of paper and it would be stupid to type all the 90 combos with prices in a post so im just giving examples..

anyways, with the above table, it is clear that i will have to use arrays...but i really dont know how!?
I know its sumthin like
DIM A(90)
LET A(1) = 2
LET A(2) = 5
Etc..

But then to get the table i would need to use a double dimension Array which is more confusing

Help!!!
Logged
Janesh
Member
*
Posts: 64


« Reply #16 on: September 07, 2003, 03:55:24 AM »

Ok..i spent loads of time and wrote down the whole table with the PRICES so you get an idea :
[it may look confusing but its the best i can do]
       AMD   BAN   CHE   COC    COI    DEL    GOA    KOL    MAN   MUM
AMD  X    5000   6000   6500  6300  4780  6400  8000  7000  3200
BAN 5000  X       2795  3020  2255  8710  3785  9155  2555  4485
CHE 6000  2795   X      4240  3225  8960  5640  7825  5100  6215
COC 6500  3020  4240   X   2500 11975  4600 13300  6200  6215
COI 6300  2255  3225 2500   X   10715  6155 11370  4765  5620
DEL 4780  8710  8960 11975 10715  X    9100  6925  9200  6095
GOA 6400  3785  5640  4600  6155  9100  X   12600  3100  3005
KOL 8000  9155  7825 13300 11370  6925 12600 X    11200  8100
MAN 7000  2555  5100  6200  4765  9200  3100  11200  X   4280
MUM 3200 4485  6215   6215  5620  6095 3009  8100  4280  X
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #17 on: September 07, 2003, 01:58:02 PM »

If the rate is determined by distance, and you know the coordinates of each city, you can make yourself a formula instead of plugging in the numbers into a 2D array, like this:

Code:

DIM SHARED city.amount%: city.amount% = 10
DIM SHARED price.to.city%(1 TO city.amount%, 1 TO city.amount%)
DIM SHARED city.name$(1 TO 2, 1 to city.amount%) '(2) is (0 TO 2)
price.to.city%(1, 1) = 0
price.to.city%(1, 2) = 5000
price.to.city%(1, 3) = 6000
price.to.city%(1, 4) = 6500
price.to.city%(1, 5) = 6300
price.to.city%(1, 6) = 4780
price.to.city%(1, 7) = 6400
price.to.city%(1, 8) = 8000
price.to.city%(1, 9) = 7000
price.to.city%(1, 10) = 3200

'And do the same for the rest of the cities....

city.name$(1, 1) = "AMD"
city.name$(1, 2) = "BAN"
city.name$(1, 3) = "CHE"
city.name$(1, 4) = "COC"
city.name$(1, 5) = "COI"
city.name$(1, 6) = "DEL"
city.name$(1, 7) = "GOA"
city.name$(1, 8) = "KOL"
city.name$(1, 9) = "MAN"
city.name$(1, 10) = "MUM"
city.name$(2, 2) = "Bangladesh"

'And do the same for the rest of the cities....

'---------------------------------------

INPUT city.name.from$
INPUT city.name.to$
city.name.from$ = UCASE$(city.name.from$)
city.name.to$ = UCASE$(city.name.to$)

FOR i% = 1 to 2
FOR j% = 1 to city.amount%
temp$ = UCASE$(city.name$(i%, j%))
IF city.name.from$ = temp$ THEN city.from% = j%
IF city.name.to$ = temp$ THEN city.to% = j%
NEXT j%, i%

PRINT price.to.city%(city.from%, city.to%)
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Janesh
Member
*
Posts: 64


« Reply #18 on: September 08, 2003, 02:31:51 PM »

HELP!!!! i did not understand what you said Agamemnus..
Could you  guide me line by line plz!!!





i thought about the array more and said, why dont i make each city, like 1,2,3,4 right..
so then the place ur goin from would be: 2
your destination would be : 3
So now i want the program to look up the array to slot 2,3 and print the value of that particular flight
Get it ?
Lol, i guess its the same thing youve done but i need it to be simplified as i cannot understand your code...!
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #19 on: September 08, 2003, 04:47:30 PM »

It's as simple as possible and does exactly what you just said. It matches up two different name sets (short and long form) with numbers... What parts don't you get.........?
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Janesh
Member
*
Posts: 64


« Reply #20 on: September 09, 2003, 01:09:44 AM »

DIM SHARED city.amount%: city.amount% = 10
DIM SHARED price.to.city%(1 TO city.amount%, 1 TO city.amount%)
DIM SHARED city.name$(1 TO 2, 1 to city.amount%) '(2) is (0 TO 2)

didnt quite get that

city.name.from$ = UCASE$(city.name.from$)
city.name.to$ = UCASE$(city.name.to$)

that

IF city.name.from$ = temp$ THEN city.from% = j%
IF city.name.to$ = temp$ THEN city.to% = j%

and that
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #21 on: September 09, 2003, 08:22:41 AM »

>DIM SHARED city.amount%: city.amount% = 10
>DIM SHARED price.to.city%(1 TO city.amount%, 1 TO city.amount%)
>DIM SHARED city.name$(1 TO 2, 1 to city.amount%) '(2) is (0 TO 2)

SHARED means that the array is accessible in all subs and functions; it is global.

% added to a variable means it is an signed INTEGER, a number with a value from -32768 to 32767.

array1(10, 10) is an array with two dimensions from 0 to 10.
array1(4 TO 10, 4 TO 10) is an array with 2 dimensions from 4 to 10.

>city.name.from$ = UCASE$(city.name.from$)
>city.name.to$ = UCASE$(city.name.to$)

$ is a string variable. UCASE$ makes all the letters of what's inside it uppercase. This is necessary to compare the city names to your own list of city names. ("Bangladesh" should actually be "BANGLADESH"..)

>IF city.name.from$ = temp$ THEN city.from% = j%
>IF city.name.to$ = temp$ THEN city.to% = j%

This compares both of the cities and, if the city matches temp$, which is the city with index j%, it gets the current j% to later get:

price.to.city%(city.from%, city.to%)
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Janesh
Member
*
Posts: 64


« Reply #22 on: September 10, 2003, 10:43:17 AM »

yeah, it does work but theres still one problem

see, where ive been taught QB, all these commands have not been used and ppl get very suspicious if i use extra commands..

i know it sounds stupid but still we have been taught only :
DIM (a,b)
OPEN blah blah blah
INPUT #
CLOSE
Etc.
And of cource basic commands and loops

So i dont want to sound dumb or anything but i SERIOUSLY cant use the code uve givin!!
Logged
Neo
Na_th_an
*****
Posts: 2150



« Reply #23 on: September 10, 2003, 11:04:36 AM »

EXACTLY which commands haven't you had yet? So then we can see what we can do for you.
Logged
Janesh
Member
*
Posts: 64


« Reply #24 on: September 11, 2003, 01:36:06 AM »

the command in Agamemnus' code :DIM SHARED has not been taught to us
Logged
Shogun
Ancient QBer
****
Posts: 411



« Reply #25 on: September 11, 2003, 07:50:44 AM »

you could easly look it up...
Logged
Janesh
Member
*
Posts: 64


« Reply #26 on: September 11, 2003, 08:47:38 AM »

look it up ?
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #27 on: September 11, 2003, 09:39:34 AM »

Yes....... click on the command...... then open up the help menu......

You can get rid of "shared" if you want to....
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Neo
Na_th_an
*****
Posts: 2150



« Reply #28 on: September 11, 2003, 10:34:27 AM »

Yes, if you haven't been taught how to do SUBs and FUNCTIONs yet, you can just delete the 'SHARED' and the program will still work. Smiley
Logged
Janesh
Member
*
Posts: 64


« Reply #29 on: September 12, 2003, 12:36:41 AM »

ohh ok..lol im so stupidd!
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!