I use windows xp and dev c++ 4.9.9.2 compiler and my programs constantly close after scanf or printf so I have been using getchar(); to keep the program from automatically closing.
I know getchar(); isn't a good method because I can press letters and they will appear on the screen but if I press enter the program will then exit.
In this example I had to use getchar twice. The book I am reading uses unix and a different compilers and doesn't provide any help for my issue.Code:#include <stdio.h> main() { int a , b ,x , y , f , ; printf("Formula f = (a-b)(x-y)\n\n"); printf("Please enter the value of a: "); scanf("%d", &a); printf("\nPlease enter the value of b: "); scanf("%d", &b); printf("\nPlease enter the value of x: "); scanf("%d", &x); printf("\nPlease enter the value of y: "); scanf("%d", &y); f = (a - b)*(x-y); printf("\nThe value of f is %d",f); getchar(); getchar(); }



LinkBack URL
About LinkBacks




