BBC BASIC for Windows
Programming >> Database and Files >> Filing Problem http://bb4w.conforums.com/index.cgi?board=database&action=display&num=1418115647 Filing Problem
Post by tomwalford on Dec 9th, 2014, 08:00am
One of my students has an issue with a problem he has been set (by me) and I'm struggling to see why his code doesn't work.
It is as follows:
Enter a name for a recipe Enter the number of people it's for Enter the ingredients (item, amount, unit)
Save the results to a file
Code is as follows
I know it will "fail" when putting the numbers into the file (as it will replace them with ASCII equivalents, but it comes up with Mistake when the name of the recipe is saved down
Any ideas?
Tom.
INPUT "Enter the name of the recipe: ";repname$
REPEAT INPUT "Enter the number of people it is for: " ;numofpeople% UNTIL numofpeople%>0
REPEAT INPUT "How many ingredients does it need?: " ;ingnumber UNTIL ingnumber>0
DIM ingredient$(ingnumber) DIM ingredient%(ingnumber) DIM unit$(ingnumber)
FOR x=1 TO ingnumber INPUT "Name of Ingredient: " ingredient$(x) INPUT "How much do you need (no units needed): " ingredient%(x) INPUT "Units: " unit$(x)
NEXT
PRINT
REM Creating the file to store the data
INPUT "Enter the filename: " filename$
filename$ = filename$ + ".TXT"
PRINT filename$
channel% = OPENOUT(filename$)
PRINT channel%
PRINT#channel%,"Recipe Name is " PRINT#channel%,repname$
FOR y=1 TO ingnumber
PRINT#channel%,"Number of people it will serve " numofpeople%
PRINT#channel%,"The number of ingredients " ingnumber
PRINT#channel%,"Name of ingredient: " ingredient$(y)
PRINT#channel%,"Amount needed: " ingredient%(y)
PRINT#channel%,"Units: " unit$(y)
NEXT
CLOSE#channel%
PRINT "File ";filename$;" has been created successfully" Re: Filing Problem
Post by DDRM on Dec 9th, 2014, 08:52am
Hi Tom,
By inserting PRINTs in varied places, it appears that the problem actually arises when you get to the
Code:
PRINT#channel%,"Number of people it will serve " numofpeople%
The problem is you have a string and then a variable with no separator. Try sticking a comma in (for each of those lines).
As you say, you'll need to use STR$(num) to convert the numbers to ascii equivalents.
best wishes,
D
Re: Filing Problem
Post by rtr2 on Dec 9th, 2014, 12:09pm