updated calculator to use while