Newbie need help in making table...
Moderators:Administrator, Global Moderator
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
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
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 :
The number of the appearance of these statements depends on the first input, which is 3, so if i enter 6, it'd show :
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 :
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...
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
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
Code: Select all
Enter 1st item : A
Enter 2nd item : A
Item already chosen, please choose the other
Enter 2nd item :
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...
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.
This is what i got so far...
running the code would give you this :
But, i want it to be like this :
how do i do that?
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
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 :
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
str$
Look up the STR$() function.
Also, remember you can print more than one constant or variable with the PRINT command.
Such as:
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."
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:
As to your last piece of code,
what you want is more like this:
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 ).
Code: Select all
1 print "Enter number of items to buy (1-8)" : input S
Code: Select all
for X = 0 to S
print "Enter 1st item" input Y
next X
Code: Select all
FOR X = 1 to S
PRINT "Enter item #";S
INPUT Y$(S)
NEXT X
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.
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??
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??