   Looping issue
  Why won't this loop end when a non-perfect square is entered?#include <stdio.h>int main(void){int N, root = 0, perfect = 0;printf("Enter an integer: ");scanf("%d", &N);while(perfect != 1 || N > root * root){if(N == root * root){perfect = 1;printf("The perfect square of %d is %d.\n", N, root);}elseroot++;}system("PAUSE");return 0;}
  i thought that || should be an &&...although this messes up the cases where the number has a perfect square for some reason   ;  while(perfect != 1 && N >= root * root)   ;  thanks, i knew it was something stupid I was missing.   ;Quote:Original post by darthstrifeWhy won't this loop end when a non-perfect square is entered?*** Source Snippet Removed ***Your loop would be simpler if you only test for the one thing:while (root*root < N){  ++root;}if (root*root == N){  // whoosiiiii!}Obviously, that doesn't explain why your loop is not working :)The loop is not working because either perfect!=1 or N>root*root is true when you enter a non perfect square. When N<root*root, perfect has to be 1, but it is never the case since you are not processing a perfect square.So... see my simpler loop above :)Regards,   ;  yeah i know it would be simpler but i need the perfect in there....i simplified the code here for clarity but in the actual program i was using pointers and perfect served a purpose...thanks everyone   ;Quote:Original post by darthstrifein the actual program i was using pointers and perfect served a purpose...thanks everyoneNo, it didn't. :) (Hint: just 'break' from the loop)   