Loading...

if else - part 3

Primary pupil or not?

BOB3 should now tell you if you’re a primary school pupil or not!

Tell him your year of birth and BOB3 will decide!

If you’re a primary school pupil, his eyes will be orange, otherwise they’ll be blue!

For our programme we need a variable, birthyear. This variable is used to store your year of birth and access it later on.

To declare a new variable, i.e. to create it, we need to define the type and name, like we do in line 12:

int birthyear;

The variable is an integer, also int. You use this type for a number without a decimal point, like 3 or 100 or 2010 etc.

We’ve chosen the name birthyear because it’s what we want to store!

In line 13 our new variable is initialised, which means it has been given a value for the first time:

birthyear = 2008;

The compiler now sees birthyear as being equal to 2008.

From this point, we can use our variable in the trueth detecor (lines 16 - 22)!

Compile the program and transfer it to your BOB3.
1: Which code is correct?
 You haven’t completed anything yet!
 Super, so far so good…
 Super, you got it all right!
 Sadly not correct…
 One answer is correct
 A couple are correct…