/* * simple program illustrating integer I/O * * revision of previous example but including error checking. */ #include #include int main(void) { int x = 10; int y = x*2; /* * simple example of printing integer values */ printf("x = %d, y = %d\n", x, y); /* * simple examples of prompting for integer values * notice the "&" in front of the target variable name -- * we will talk later about what this means, but for now * just be aware that it is needed! */ printf("enter x\n"); if (scanf("%d", &x) != 1) { printf("not a number\n"); return EXIT_FAILURE; /* defined in stdlib.h */ } printf("enter y\n"); if (scanf("%d", &y) != 1) { printf("not a number\n"); return EXIT_FAILURE; } printf("x = %d, y = %d\n", x, y); printf("enter x, y\n"); if (scanf("%d %d", &x, &y) != 2) { printf("not a number\n"); return EXIT_FAILURE; } printf("x = %d, y = %d\n", x, y); return 0; }