I'm very new to C language, I have the following code: Code: #include <stdio.h> #include <stdlib.h> int number; int total; int nums=0; int i; char c; int main() { for(;;) { printf("please enter number here, and character k to quit:\n"); fflush(stdin); scanf("%d",&number); total +=number; nums++; } printf("average value: %d\n",total/nums); return(0); } Now I want is that when user type 'k' from keyboard, above loop will break. Could anyone modofy my source code so that I can learn from you? Thanks and regards,
Code: char ch; for(; { printf("Want to quit then Press k Key\n"); fflushstdin); scanf("%c",&ch); if(ch=='k') break; printf("please enter number here:\n"); fflush(stdin); scanf("%d",&number); total +=number; nums++; } I dont know what you want. lot of different ways you can doit. Just tell If you want something different?