hey guys im learning to make my own functions and iv had a little trouble it seems my function is returning what i want but for some reason when i put it in a do while loop it just keeps looping instead of exiting when i want, you should be able to see what i mean from this sample text. Thanks in advance much appreciated the people on this site are so helpful.
for some reason it just keeps looping even if something other than y or Y is entered.Code:#include <stdio.h> const int TRUE = 1; const int FALSE = 0; int isY(char ch); int main() { int x = 1; int choice; while (x = 1) { choice = isY(choice); if (choice == FALSE) x++; } return 0; } int isY(char ch) { int result; printf("Say this massage again\n(Y/N)? "); scanf("%c", &ch); fflush(stdin); printf("\n"); if ( (ch == 'y') || (ch == 'Y') ) result = TRUE; else result = FALSE; return result; }
p.s. fflush(stdin) works fine on my compiler (quincy 2005) and i have not yet been tought a better way to flush the standard input thing, but that should not be the problem here. thanks again