Try using methods
a method for writting the input
and a method for doing the calculations den call those methods by creating objects of this class it sholud work...