SB Curriculum exercise 1.5 branching and subroutines.

# SB Curriculum exercise 1.5 branching and subroutines.

• Wednesday, July 18, 2012 10:42 PM

Hello

SB Curriculum ex 1.5 - the given solution - doesn't seem to work as required.

One possible solution - link below - lot's of room for improvement I know :)

http://smallbasic.com/program/?QZZ154

The solution given in the curriculum determines hot, cold etc based on the temp. entered by the user - my solution prompts the user for hot, cold etc.

I've not used a branch (goto), not sure that there's a need for one, although..... it's one possible way to tackle the problem of displaying a zero count correctly...I'll have a look tomorrow.

### All Replies

• Thursday, July 19, 2012 11:01 AM

The problem with zero count can be resolved by initialyzing the variables to 0 (zero).

Check the following program:

ans=0

It seems not very efficient to ask for every city to fill in the words "rainy" or "windy".

When you make a typing error the counting doesn't work not good.

It is better to ask for a one letter answer e.g.  r for rainy,  w for windy etc.

or use a numerical answer  1 for cold, 2 for cool etc.

Jan [ WhTurner ] The Netherlands

• Thursday, July 19, 2012 4:33 PM

Hi Thanks for the reply. And the tip for the zero count.

Yes there's lt's of room for error in asking for all of the conditions to be typed in full/ A single digit or letter would be better.

Paul

• Thursday, July 19, 2012 7:50 PM

http://smallbasic.com/program/?CZX934 - this works :)

adopted the temp input and conversion to hot. cold etc

Initialized the hot, cold etc, variables - very simply at the start of the program.

subroutines are called within the while loop and do what they're supposed to do.

now how many cities are hot and windy... mmmmmm