Confused where to use if conditions within the while loop

Your code only had issues with output format, otherwise it was fine. Here is your corrected code https://ide.codingblocks.com/s/268985