Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help me!
#11
They're all based on the same variables.

The Program im coding should print out the list of album names and artist names, along with a number, so the user inputs a number and it prints out the albums name and artists name.

It looks sumthin like this :
Code:
PRINT "1:[Album]      -[Artist]"
PRINT "2:[Album2]    -[Artist2]
`it goes on
INPUT "Your Option ?";number
IF number = 1 THEN LET album$ = "Album" : LET artist$ = "Artist"
IF number = 2 THEN LET album$ = "Album2" :LET artist$ = "Artist2"


You'll get the idea
Reply
#12
They're all based on the same variables.

The Program im coding should print out the list of album names and artist names, along with a number, so the user inputs a number and it prints out the albums name and artists name.

It looks sumthin like this :
Code:
PRINT "1:[Album]      -[Artist]"
PRINT "2:[Album2]    -[Artist2]
`it goes on
INPUT "Your Option ?";number
IF number = 1 THEN LET album$ = "Album" : LET artist$ = "Artist"
IF number = 2 THEN LET album$ = "Album2" :LET artist$ = "Artist2"


You'll get the idea
Reply
#13
Janesh,
Who decides what number is assigned to an album/artist?
According to your example, your program is deciding. If I were using your program, how do I know what the number is for my favorite album/artist?

I think what you need is a "master file" set up by the user, where he assigns the numbers. Then he gives the number to your program and you go get the album/artist.
Think about it.
*****
Reply
#14
this program has nothing to do with favorates or anything

goto http://forum.qbasicnews.com/viewtopic.php?t=3961
to find out more!!
Reply
#15
Quote:They're all based on the same variables.

The Program im coding should print out the list of album names and artist names, along with a number, so the user inputs a number and it prints out the albums name and artists name.

It looks sumthin like this :
Code:
PRINT "1:[Album]      -[Artist]"
PRINT "2:[Album2]    -[Artist2]
`it goes on
INPUT "Your Option ?";number
IF number = 1 THEN LET album$ = "Album" : LET artist$ = "Artist"
IF number = 2 THEN LET album$ = "Album2" :LET artist$ = "Artist2"


You'll get the idea

You need to use something like this:
Code:
'jkc 2003

TYPE album
   albumname AS STRING * 30
   artist AS STRING * 20
END TYPE
    
index = 0
DIM AlbumDBase(300) AS album   'an array of 300 albums
DO
   CLS
   PRINT "      Main Menu"
   PRINT "(E)nter album"
   PRINT "(V)iew albums"
   LOCATE 23: PRINT index; " albums in dbase"


   DO
     a$ = INKEY$
   LOOP UNTIL a$ <> ""
  
   SELECT CASE UCASE$(a$)
      CASE "E"
        CLS
        PRINT "      Album Enter Screen"
        GOSUB enterIt
      CASE "V"
        CLS
        PRINT "      Album View Screen"
        GOSUB viewIt
      CASE ELSE
        LOCATE 10, 10: PRINT "Choose a valid selection"
        t = TIMER + .75: DO: LOOP UNTIL TIMER > t
   END SELECT
LOOP

END

enterIt:
  INPUT "Album Name? (30 characters max) ", t$
  IF t$ = "" THEN
      RETURN
  ELSE
      index = index + 1
      AlbumDBase(index).albumname = t$
  END IF
  INPUT "Artist? (20 chars max)"; AlbumDBase(index).artist
  
  PRINT
  PRINT "Next album?  <ENTER> return to Main Menu"
  GOTO enterIt
RETURN

viewIt:
  CLS
  PRINT "   Album                                  Artist"
  FOR i = 1 TO index
    PRINT i; AlbumDBase(i).albumname, AlbumDBase(i).artist
  NEXT i
  PRINT "Any key to continue..."
  SLEEP
RETURN

Now...you can get random access to your albums...eg you could have a line of code somewhere that said:
Code:
Input "number of album you want to see",selection
print selection; AlbumDBase(selection).albumname, AlbumDBase(selection).artist

and you don't need to screw with any more conditional statements.
Reply
#16
dont you think what youve done is a bit too complicated ?
Reply
#17
Try it Smile Complicated though it may seem, it's much easier to understand than a million ifs.
Reply
#18
Quote:dont you think what youve done is a bit too complicated ?

What I've "done" is try to *help* you!! Big Grin

Seriously, I wrote the program in about 15 minutes and posted it"untested"...then decided to test it...there was only 1 bug...in the viewIt subroutine, I mistakenly used the variable index as the array subscript, instead of i. I then decided to clean up the interface a bit and spent 15 min more...trying to *help* you.

The sample code is easy to follow and allows you to learn the basics of:

TYPE structures
Arrays
block IF/THEN
Select case
and demonstrates the usefulness of modularity (although you would really use SUBs instead of GOSUBs.
Inkey$
simple menus.
nested loops

These are all very important programming concepts.

If you are *interested*, to be useful, you would want to make this program output the array to a file...and read the file back into the array when the program is run...so that you would never have to enter the same text twice. This feature would be simple to implement whenever you are ready for file I/O.

Allowing Humans to avoid performing the same task many times is the *whole point* of computers. If you wrote the program using a unique variable name for each album, and then use conditional IF/THEN statements for each one...you'd have a lot more typing to do in the code, and each time you wanted to add another album, you'd have to modify the code...which is not my idea of a well-designed or well-written program :roll:

Using an array of TYPEs may be too complicated if you don't yet understand arrays.

See the following for a simple program that uses arrays:


Code:
CLS
DEFINT M  'forces min & max to integers...not really needed
min = 1
max = 5

DIM myArray(min TO max) AS SINGLE   'creates 5 variables...all at once

PRINT "Please enter "; max; " numbers"
FOR index = min TO max STEP 1
    PRINT "Enter #"; index;
    INPUT myArray(index)
NEXT index
PRINT : PRINT
PRINT "Great...I have my numbers. Want to see them?"
SLEEP
PRINT : PRINT
PRINT "Here they are"
GOSUB showArray


PRINT "want to see them in reverse order?"
SLEEP
FOR i = max TO min STEP -1
   PRINT myArray(i);
NEXT i
PRINT : PRINT
PRINT "Now...I'll print the double of each value"
SLEEP
FOR i = min TO max
   PRINT myArray(i) * 2;
NEXT i
PRINT : PRINT
PRINT "But...The original values remain"
SLEEP
GOSUB showArray

PRINT "Now, I'll double each value"
SLEEP
FOR i = min TO max
   myArray(i) = myArray(i) * 2
NEXT i
GOSUB showArray

PRINT "Now...let's order these values"
SLEEP

DO
  noswap = 1
  FOR i = min TO max - 1
     IF myArray(i) > myArray(i + 1) THEN
       SWAP myArray(i), myArray(i + 1)
       noswap = 0
     END IF
  NEXT i
LOOP UNTIL noswap = 1
PRINT "ta da...They are in ascending order"
GOSUB showArray

PRINT : PRINT
PRINT "Over and Out!!"
END

showArray:
FOR i = min TO max
   PRINT myArray(i);
NEXT i
PRINT : PRINT
RETURN
Reply
#19
Quote:this program has nothing to do with favorates or anything

goto http://forum.qbasicnews.com/viewtopic.php?t=3961
to find out more!!

Janesh,
As Mango has already figured out, you make it tough to help you. Your requests are not clear nor complete, plus you question and criticise efforts to help you. Do you really want help?
*****
Reply
#20
just because i dont reply to *ALL* the posts does not mean that i dont respect and appreciate what the person has posted.

What mango wrote really helped me. Actually all the posts helped me and i got what i wanted.
So now i thought this post had gotten old, so i didnt want to repost a messege on it.

and about the :
Quote:this program has nothing to do with favorates or anything

goto http://forum.qbasicnews.com/viewtopic.php?t=3961
to find out more!!


i wrote that so that he could understand better what i had in mind.


While im at it, thanks mango for posting, it really helped.


P.S :uhm..moneo..i think you misunderstood me!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)