# First Time Programming Ever - Stuck on 1.5 branching and subroutines

• ### Question

• Hey everybody,

This is my first attempt ever at programming. I have been following along in the small basic curriculum and I am stuck on 1.5 Branching and Subroutines. I have been trying to solve the last problem. The solution provided is not running. It says the subroutine suboutput is not defined.

can somebody help me? this is the source code

up:

If i < 10 then

TextWindow.WriteLine("")

TextWindow.Write("What is the name of a city? ")

TextWindow.Write("How warm is that city (in degrees Celsius)? ")

TextWindow.Write("Is it rainy (Y/N)? ")

TextWindow.Write("Is it windy (Y/N)? ")

'Calling subroutines

subtempCount()

subrainyCount()

subwindyCount()

i = i + 1

If i = 10 Then

subOutput()

EndIf

EndIf

Goto up

Sub subtempCount

If temp <= 5 Then

ColdCount = ColdCount + 1

ElseIf temp <= 15 Then

CoolCount = CoolCount + 1

ElseIf temp <= 25 Then

WarmCount = WarmCount + 1

Else

HotCount = HotCount + 1

EndIf

EndSub

Sub subRainyCount

If Rainy = "y" Or Rainy = "Y" Then

RainyCount = RainyCount + 1

EndIf

EndSub

Sub subWindyCount

If Windy = "y" Or Windy = "Y" Then

WindyCount = WindyCount + 1

EndIf

EndSub

Thursday, June 23, 2011 9:56 PM

• What that means is that there is NO subroutine that is for output. Most likely, you did not copy all of the code in the curriculum. If there is anything that says:

Sub output

Then copy and paste that subroutine to the end of your code.

~~AirWaves!!~~
Friday, June 24, 2011 12:53 AM
• Just to give you an idea this is how I would start writing this program (There is no wrong or right way) Just makes it a lot simpler to manage.

```'Main loop
For i = 1 To 10
CityInput()
EndFor

CityOutput()

'Subroutines
Sub CityInput
TextWindow.WriteLine("What is the name of the city?")
TextWindow.Write(">>: ")
TextWindow.WriteLine("")
CityInputCheck()
EndSub

Sub CityInputCheck
If CityName = "" Then
TextWindow.WriteLine("Enter a valid city name!")
TextWindow.WriteLine("")
CityInput()
Else
CityPassed()
EndIf
EndSub

Sub CityPassed
CityInput[i] = cityname
EndSub

Sub CityOutput
TextWindow.Clear()
For j = 1 To 10
TextWindow.WriteLine("City: " + CityInput[j])
EndFor
EndSub
```

Friday, June 24, 2011 7:52 AM

### All replies

• Hi Palmos,

When your counter i = 10 you are calling the subroutine  subOutput() however you have not defined this subroutine so the computer doesn't know what to do.

Also for a bit of advice your using a label and goto statement, you could easily make this easy to understand with a for loop

like this:

```For i = 1 to 10
TextWindow.WriteLine("")

TextWindow.Write("What is the name of a city? ")

TextWindow.Write("How warm is that city (in degrees Celsius)? ")

TextWindow.Write("Is it rainy (Y/N)? ")

TextWindow.Write("Is it windy (Y/N)? ")

'Calling subroutines

subtempCount()

subrainyCount()

subwindyCount()

endfor

'Here you will need your output subroutine.

Sub subtempCount

If temp <= 5 Then

ColdCount = ColdCount + 1

ElseIf temp <= 15 Then

CoolCount = CoolCount + 1

ElseIf temp <= 25 Then

WarmCount = WarmCount + 1

Else

HotCount = HotCount + 1

EndIf

EndSub

Sub subRainyCount

If Rainy = "y" Or Rainy = "Y" Then

RainyCount = RainyCount + 1

EndIf

EndSub

Sub subWindyCount

If Windy = "y" Or Windy = "Y" Then

WindyCount = WindyCount + 1

EndIf

EndSub```

You might want to watch your formating as well, I have not changed any of this you can fix this. :)

Also might be a good idea when getting input from a user, maybe have some kind of check/validation to see if the input was the correct data the program is looking for.

E.G When you are asking the user if it's raining you are checking if they put "y" or "Y". You can use this rainy = text.ConvertToLowerCase(TextWindow.Read()) so it converts the input straight to lowercase so you only need to check for "y"

Hope this helps.

• Edited by Thursday, June 23, 2011 10:43 PM
Thursday, June 23, 2011 10:32 PM
• hey kirkkaf,

i appreciate the feedback. The solution i provided is not my source code. It is a source code provided in the small basic curriculum. It says the subroutine output is not defined, because it was never defined. (The creators of the small basic curriculum must have not defined it). I do not know how to define it.

I am not yet up to the part with loops. I am only on 1.5 of the curriculum. I wanted to see the program run, but I cant get it to run because the subroutine output was not defined.

If someone can define it for me, that would be great.

Thursday, June 23, 2011 10:38 PM
• What that means is that there is NO subroutine that is for output. Most likely, you did not copy all of the code in the curriculum. If there is anything that says:

Sub output

Then copy and paste that subroutine to the end of your code.

~~AirWaves!!~~
Friday, June 24, 2011 12:53 AM
• Apologies Palmos I have not completed this myself. Here is the original source code you posted with my output subroutine.

```up:

If i < 10 then

TextWindow.WriteLine("")

TextWindow.Write("What is the name of a city? ")

TextWindow.Write("How warm is that city (in degrees Celsius)? ")

TextWindow.Write("Is it rainy (Y/N)? ")

TextWindow.Write("Is it windy (Y/N)? ")

'Calling subroutines

subtempCount()

subrainyCount()

subwindyCount()

i = i + 1

If i = 10 Then

subOutput()

EndIf

EndIf

Goto up

Sub subtempCount

If temp <= 5 Then

ColdCount = ColdCount + 1

ElseIf temp <= 15 Then

CoolCount = CoolCount + 1

ElseIf temp <= 25 Then

WarmCount = WarmCount + 1

Else

HotCount = HotCount + 1

EndIf

EndSub

Sub subRainyCount

If Rainy = "y" Or Rainy = "Y" Then

RainyCount = RainyCount + 1

EndIf

EndSub

Sub subWindyCount

If Windy = "y" Or Windy = "Y" Then

WindyCount = WindyCount + 1

EndIf

EndSub

sub subOutput
textwindow.clear()
textwindow.writeline("There are " + ColdCount + " cold cities")
textwindow.writeline("There are " + CoolCount + " cool cities")
textwindow.writeline("There are " + WarmCount + " warm cities")
textwindow.writeline("There are " + HotCount + " hot cities")
endsub```

As you can see I added a simple subroutine called subOutput as named in your source code you provided.

This will display how many city names were entered how many are hot, cool and warm. I'm sure you can figure out how to display all the windy and rainy cities.

If you was to use arrays instead of variables you would be able to write your output like:

City: London
Temperature: Cold
Windy: Yes
Raining: No

for all your cities but because every loop the variable is replaced with new input.

Hope this helps.

Friday, June 24, 2011 7:29 AM
• Just to give you an idea this is how I would start writing this program (There is no wrong or right way) Just makes it a lot simpler to manage.

```'Main loop
For i = 1 To 10
CityInput()
EndFor

CityOutput()

'Subroutines
Sub CityInput
TextWindow.WriteLine("What is the name of the city?")
TextWindow.Write(">>: ")
TextWindow.WriteLine("")
CityInputCheck()
EndSub

Sub CityInputCheck
If CityName = "" Then
TextWindow.WriteLine("Enter a valid city name!")
TextWindow.WriteLine("")
CityInput()
Else
CityPassed()
EndIf
EndSub

Sub CityPassed
CityInput[i] = cityname
EndSub

Sub CityOutput
TextWindow.Clear()
For j = 1 To 10
TextWindow.WriteLine("City: " + CityInput[j])
EndFor
EndSub
```

Friday, June 24, 2011 7:52 AM