Newbie need help in making table...

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Sieghart
Newbie need help in making table...

Post by Sieghart » Sun Feb 19, 2006 7:36 am

Hi, i'm new here...
How do i make a table which the number of row depends on the input?
So if I input "5" then the table would have 5 rows..
(the number of columns is fixed)
thanks in advance

Sieghart

Post by Sieghart » Sun Feb 19, 2006 8:16 am

Hmmm.. i think i'll just explain it in details...
A store sells 8 items, A,B,C,D,E,F,G,H and each has its own price.
Now whenever you run the program, it'd show the list of the items and the price (no problem here), and then you'll be asked :

Code: Select all

Enter amount of items to buy : 3
Enter 1st item : C
Enter 2nd item : B
Enter 3rd item : D
The number of the appearance of these statements depends on the first input, which is 3, so if i enter 6, it'd show :

Code: Select all

Enter 1st item : C
Enter 2nd item : B
Enter 3rd item : D
Enter 4th item : H
Enter 5th item :A
Enter 6th item : F
How do i do this? One more thing, there can't be 2 of the same item, so if i've selected A on the first selection, i can't select it again, BUT i don't want it to redo from the start (error message) maybe it'd better if it looks like this :

Code: Select all

Enter 1st item : A
Enter 2nd item : A
Item already chosen, please choose the other 
Enter 2nd item :
Any idea how to do this?
And lastly after the selection is done, i plan to make the table which shows the list of the item + their price and the total price, i don't have any problems in drawing tables, but i don't know how to make the row extended based on the number of items... so if i entered 3 on the first input, there'd be 4 rows (1 for name/price,etc) and if i entered 6, there'd be 7.

Sorry if i ask too much...

Ralph
QBasic God
Posts:134
Joined:Sat Nov 06, 2004 2:27 am
Location:Katy, Texas

Post by Ralph » Mon Feb 20, 2006 3:52 am

So far, you have only described what you would like to have. But, we shouldn't be solving your problem for you so totally! Please show the code you have developed so far, and where you are having a problem (or problems), and you will get help.
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.

Guest

Post by Guest » Mon Feb 20, 2006 11:28 pm

This is what i got so far...

Code: Select all

dim S as integer 
dim S as integer 
dim X as integer 

1 print "enter amount of item to buy" : input S 
if S<1 then 
goto 1 
elseif S>8 then 
print "Too many items" 
goto 1 
end if 

for X = 0 to S 
print "Enter 1st item" input Y 
next X 
running the code would give you this :

Code: Select all

enter amount of item to buy : 6 
Enter 1st item : 
Enter 1st item : 
Enter 1st item : 
Enter 1st item : 
Enter 1st item : 
Enter 1st item : 
 
But, i want it to be like this :

Code: Select all

enter amount of item to buy : 6 
Enter 1st item : B 
Enter 2nd item : C 
Enter 3rd item : A 
Enter 4th item : F 
Enter 5th item : E 
Enter 6th item : D  
how do i do that?

RyanKelly

str$

Post by RyanKelly » Tue Feb 21, 2006 5:16 am

Look up the STR$() function.
Also, remember you can print more than one constant or variable with the PRINT command.


Such as:

Code: Select all

PRINT "I have"; x;" years of my sentence left to serve."

Ralph
QBasic God
Posts:134
Joined:Sat Nov 06, 2004 2:27 am
Location:Katy, Texas

Post by Ralph » Tue Feb 21, 2006 5:52 am

Since you apparently want to limit the maximum amount of items to enter to eight, why not let the person know, in your line 1, thus:

Code: Select all

1 print "Enter number of items to buy (1-8)" : input S 
As to your last piece of code,

Code: Select all

for X = 0 to S 
print "Enter 1st item" input Y 
next X 
what you want is more like this:

Code: Select all

FOR X = 1 to S
  PRINT "Enter item #";S
  INPUT Y$(S)
NEXT X
Note that, since you will be inputting a letter, you must use te Y variable as a string variable, Y$, and, since you expect different values of Y$, you must use an array, say Y$(8 ).
Last edited by Ralph on Tue Feb 21, 2006 5:55 am, edited 1 time in total.
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.

Guest

Post by Guest » Sun Apr 16, 2006 5:50 am

here is how I would do this:
first start qbasic with the /ah command , to enable dynamic arrays mode...
the make the programs thusly:
rem $dynamic
input " how many items would you like to buy ? 1-8) ";z%
dim shoplist(1 to z%) as string*1
for indx% = 1 to z%
input"item to buy ";shoplist(indx%)
next indx%


and when you no longer need this shopping list you can say;
erase shoplist()
or to redim it to another size like for another customer
input "how many items would you like to buy ";z%
redim shoplist(1 to z%)
and if you would like to include prices and other information
if the shoplist() array is string based you would need another array for
values / numbers
or you could make a user defined type like this
type basket
shoplistitem as string*1
shoplistprice as single
shoplistquantity as single
and so on
end type
then you
dim usrbasket(z%) as type basket
then to enter an item you use usrbasket.shopitem(indx%)
and so on .....
does this help at all??


:)

Post Reply