yeah, my problem here, is to make sure that a user enters an integer only...Code:#include <stdio.h> int main(void) { int ch; printf ("Press [Enter] to continue"); while ((ch = getchar()) != '\n' && ch != EOF); return(0); }
browsing thru the forum, that code stood out... using the getchar() function..
could you tell me what i would do in the while loop to make sure a user enters an integer only?
thx.
could u explain what EOF means too?
2nd question..
lets say, my global variable is work_pay, it is a global variable because i want to access it in a few functions.
how would i assign the value of work_pay from function1, so i can access it in functions 2 and 3?
is it possible?
edit.. i htink i solved it, heres my code...
Code:#include <stdlib.h> #include <stdio.h> #include <time.h> #include <math.h> #include <string.h> int work_pay; int work_pay2; void func1(); void func2(); int main() { int count; func2(); // print data. func1(); //data entered func2(); //print new data system("PAUSE"); return 0; } void func1(){ int ans, ans1; printf("Enter a number for work_pay: "); scanf("%d",&ans); printf("enter a number for work_pay2: "); scanf("%d",&ans1); work_pay = ans; work_pay2 = ans1; } void func2(){ printf("work_pay is: %d\n\n",work_pay); printf("work_pay2 is: %d\n\n",work_pay2); }



LinkBack URL
About LinkBacks


