jenny
New Member
Posts: 4
|
Post by jenny on May 8, 2020 2:21:07 GMT
Hello everyone! I am new and this programming is hard for me but almost finished with this semester. I have a Base Code that I have to modify. I have to use four data elements, one numeric array, and one string array, and I have to utilize gosub and return. Here is my Base Code: Last=0 Dim Name$(50) 'Dim additional fields here
Do Print"A.Add Name" Print"B.List Names" Print"Q.Quit" Input "Enter Choice: ";Choice$
Select Case Choice$ Case"A" Input"Enter Name: ";Name$(Last) 'Input additional fields here Last=Last+1
Case"B" For x=0 to Last-1 Print Name$(x)'print additional fields Next x End Select Loop Until Choice$="Q" End
This is my program and it doesn't work!
Last=0 Dim Item$(50) Dim Item Number(50) Dim Price(50) Dim Qty(50)
Do Gosub[Menu] Select Case Choice$ Case "A" Gosub[AddItem] Case "B" Gosub[ListallItems] Case "Q" Gosub[Quit] End Select Loop Until Choice$="Q" End
[Menu] Print"A.Add Item" Print"B.List all Items" Print"Q.Quit" Return
[AddItem] For x=1 to 50 Input"Enter Item: ";Item$(x) (Last) Input"Enter Item Number: ";Num(x) Input"Enter Price: ";Price(x) Input"Enter Quantity: ";Qty(x) Last=Last+1 Next x Return
[ListallItems] For x=0 to Last-1 Print Item$(x),Item Number(x),Price(x),Quantity(x) Next x Print" Inventory Complete" End
It just keeps running...I need help please. Thank you
|
|
|
Post by honkytonk on May 8, 2020 10:39:23 GMT
No compound names for arrays: Dim item(50) is good Use the "C" icon in the upper band of the response window to publish code; put the code between the tags.
|
|
|
Post by honkytonk on May 8, 2020 11:43:44 GMT
No compound names for arrays: Dim item(50) is good Use the "C" icon in the upper band of the response window to publish code; put the code between the tags. Note: Capital letters are good for display, but in the code they can be confusing An other way: Dim item$(50): Dim price$(50): Dim qty$(50): Dim number$(50)
[Menu] Print"A.Add Item and price and quantity with espaces " 'Print"B.List all Items" 'Print"Q.Quit" input choice$ Select Case Choice$ Case "A" Gosub[AddItem] Case "B" Gosub[ListallItems] Case "Q" Gosub[Quit] End Select
[AddItem] x=x+1 number$(x)=str$(x) Input"Enter Item: ";item$ item$(x)= word$(item$,1) price$(x)= word$(item$,2) qty$(x)= word$(item$,3) gosub [ListallItems] goto [AddItem] wait
[ListallItems] For n=1 to x Print "N°: ";number$(n);" Name: ";item$(n);" Price: ";price$(n);" Quantity: ";qty$(n) Next n return End
|
|
|
Post by Rod on May 8, 2020 12:16:48 GMT
We try to resist giving students complete solutions. A pointer or two in the right direction is better. Also when asking for help it is better to show us the actual task you were set rather than your current interpretation of the task.
So I hope you take honkytonk's code and study it to understand what he has done to make your code work. If you just copy and paste his code you will have learned very little from the exercise.
Lecture over, enjoy your coding, it should be fun, not hard work.
|
|
|
Post by honkytonk on May 8, 2020 13:39:41 GMT
No complete solution, only bark for sharpening the claws
|
|
jenny
New Member
Posts: 4
|
Post by jenny on May 8, 2020 15:28:33 GMT
Thank you very much! I was seeking advice or help to what I was doing wrong in my coding. I was not seeking just answers. I am coding the way I did according to the teacher but will study and learn from honkytonk's coding too! I appreciate you honkytonk.
|
|
|
Post by B+ on May 8, 2020 21:31:10 GMT
Hi jenny,
This is missing the place where you INPUT "prompt"; Choice$, you gosub menu which prints menu but choice is never asked for before doing SELECT CASE on the Choice$ so that part just goes round and round in circles waiting for something for Choice$
Do Gosub[Menu] Select Case Choice$ Case "A" Gosub[AddItem] Case "B" Gosub[ListallItems] Case "Q" Gosub[Quit] End Select Loop Until Choice$="Q" End
|
|
|
Post by tsh73 on May 8, 2020 21:32:21 GMT
>>This is my program and it doesn't work! code posted just don't compile at all
EDIT and this is BAD because that means you show us one code but you work on ANOTHER code. We do not see the differences. Will you figure them out?
And (don't compile) is because of "Item Number" You really can't use space inside (variable) name. So either ItemNumber or just Num, like in your [AddItem] block, will make it run.
>>It just keeps running. That's because example program shows menu and asks for choice with
Input "Enter Choice: ";Choice$ but your program forgot about it - it shows menu over and over.
Last 1 1/2 things 1)then you want to add an item, you want to add ONE item, not 50 1/2) Input"Enter Item: ";Item$(x) (Last) is so wrong it shouldn't really compile
|
|
jenny
New Member
Posts: 4
|
Post by jenny on May 8, 2020 21:38:33 GMT
Thank you B+ for pointing that out to me...After looking at my code a million times I finally realized I missed that Input of Select Choice$. I am telling you...one simple mistake could mess up your whole program...thank you
|
|
jenny
New Member
Posts: 4
|
Post by jenny on May 8, 2020 21:45:21 GMT
Hi tsh73, I really appreciate your advice and pointing out what I missed. My teacher put in the code and I guess he expects (50) which to me is extreme, but ok...and he put in (last) which I have no understanding for. My program finally worked but when I tested it out I only used (5) because I was not about to input 50 things. Ha ha! Thank you. I really enjoy programming because it is challenging but one little thing could mess everything up. Still learning though and its hard when I am learning online through lectures only, but I am trying.
|
|
|
Post by B+ on May 8, 2020 21:45:30 GMT
"compile", you must mean interpret.
|
|
|
Post by B+ on May 8, 2020 21:49:24 GMT
Hi tsh73, I really appreciate your advice and pointing out what I missed. My teacher put in the code and I guess he expects (50) which to me is extreme, but ok...and he put in (last) which I have no understanding for. My program finally worked but when I tested it out I only used (5) because I was not about to input 50 things. Ha ha! Thank you. I really enjoy programming because it is challenging but one little thing could mess everything up. Still learning though and its hard when I am learning online through lectures only, but I am trying. 50 is sadistic! But tsh73 is right, you want to do 1 at a time, go back to menu and get list if want to see it with new item, not usually right after input a new item. Oh hey, maybe the teacher wants you to limit new items to 50, otherwise you will exceed the DIM size of your arrays. If that is the case, and it is likely it is, then you need to check you are not at the limit of 50 before adding a new item.
|
|
|
Post by tsh73 on May 9, 2020 5:44:43 GMT
"compile", you must mean interpret. Just BASIC calls it "Compile"
|
|
|
Post by Rod on May 9, 2020 7:47:16 GMT
Yes, always a two step process. First compiled to a .tkn (even one you never see) then this .tkn is passed to the runtime engine which interprets it. So Just BASIC is an interpreted BASIC, we just have an inbetween compiler step. Don’t know why but perhaps it better prepares the basic code for the Smalltalk based interpreter.
|
|
|
Post by B+ on May 9, 2020 15:15:56 GMT
Yes the reason I thought interpreted is because it will execute lines of code until it reaches a syntax error. But with jenny's code, I see it hits an error first here: Dim Item Number(50) '< error spaces not allowed in array names I hadn't noticed that right off the bat an error.
|
|