BBC BASIC for Windows
« Filing Problem »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:54pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Filing Problem  (Read 920 times)
tomwalford
New Member
Image


member is offline

Avatar




PM


Posts: 1
xx Filing Problem
« Thread started 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"
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Filing Problem
« Reply #1 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
« Last Edit: Dec 9th, 2014, 08:53am by DDRM » User IP Logged

rtr2
Guest
xx Re: Filing Problem
« Reply #2 on: Dec 9th, 2014, 12:09pm »

on Dec 9th, 2014, 08:00am, tomwalford wrote:
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.

You posted exactly the same question at BBC-BASIC-ICT and I've replied there.

Richard.
User IP Logged

rtr2
Guest
xx Re: Filing Problem
« Reply #3 on: Dec 9th, 2014, 12:44pm »

on Dec 9th, 2014, 08:52am, DDRM wrote:
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.

Just to clarify, you can do one or the other; so either of these changes will avoid the error:

Code:
PRINT#channel%, "Number of people it will serve ", numofpeople%
PRINT#channel%, "Number of people it will serve " + STR$(numofpeople%) 

I explain in my reply at BBC-BASIC-ICT some of the issues surrounding the choice between these options.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls