You need to initialize the num variable to something before you enter the loop, something like
int num = 0;
do....
while...