Two immediate problems. Loop is never initialised so while (loop !=0 ) will give you random results. And the other problem... You will end up with an infinite loop as you dont ever increment of decrement variable loop. So, the result for loop!=0 is always going to be the same. Also, your logic could be cleaned up a bit too as you dont need a hundred if's and else if's to do the job in this case. Good luck
well my suggestions begins with that good programmin practice donot make use of if else ladder instead "switch" statement is preffered instead of multiple "if's" , secondly it is another good practice to use "do while" loop in unexpected termination cases like the one urs. I disagree with above lone wolf first statement in this case u dont say " loop " variable is initialized but it is convineint to say that it is never assigned a value also the input u took with " ans " variable is not used so omit the loop variable and make use of ans variable in while loop will solve ur problem and will work fine .
Thats the same thing. What do you feel that this loop will do if loop is 'convineintly never assigned a value' or 'convineintly' never decremented or 'convineintly' never incremented. I would say that the results would be 'inconvineint' and would result in a post thread asking for help.