Scanf's return value is the number of specifiers that you give it.
how can i make my program accept 2 integers and quit if it is a non - integer value. using scanf
I've tried
Code:
while ( scanf("%d %d", &num, &num_max) == 2)
----body of code
---return (0);
}
However that still made the program terminate wrong.
Here is my code:
Code:
/* numberSQUARED.c shows a integer, its squared and cubbed sequence in a given length*/
#include <stdio.h>
#include <stdlib.h> /* system needed */
int main(void)
{
int num;
int ndx;
int num_max;
printf("Enter a min number and a max.");
scanf("%d %d", &num, &num_max);
/* format the screen */
printf("num SQUARED CUBBED\n\n");
/* output the results */
for (ndx = num; ndx <= num_max; ndx++)
{
printf("%d %6d %6d", ndx, ndx * ndx, ndx * ndx * ndx);
printf("\n");
}
printf("\n");
system("pause");
return (0);
}