int.parse using int not the calculate fomular
use foreach to fix index out of scope