Not only may you have an uninitialized variable, you're guaranteed to.
Look at your control flow: You first ask for a value for define
, and then you execute exactly one of the blocks. If define
is "boy"
, you don't initialize agirl
; if define
is "girl"
, you don't initialize aboy
, and if define
doesn't match either, you don't initialize any of your variables at all.
It looks like you are trying to cleverly combine the functions of a boolean
and an int
by having "magic" values in your int
s. This is poor design because it's not clear how the magic works, but you can make your example run by initializing all of your int
values to 0
:
int aboy = 0, agirl = 0, age = 0;