Unable to set the "Val" in second half of Code

https://ide.codingblocks.com/s/461317.

Unable to get the output. Problem lies in the second half of the code.

corrected code: