Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <time.h>
- #include <ctype.h>
- void clear(void)
- {
- while(getchar()!='\n');
- }
- double getdouble(double min, double max)
- {
- double value;
- char after;
- int rc,keeptrying = 1;
- do
- {
- printf("Enter a whole number\n"
- "in the range [%lf,%lf] : ", min, max);
- rc = scanf("%lf%c", &value, &after);
- if (rc == 0) {
- printf("**No input accepted!**\n\n");
- clear();
- } else if (after != '\n') {
- printf("**Trailing characters!**\n\n");
- clear();
- } else if (value < min || value > max) {
- printf("**Out of range!**\n\n");
- } else
- keeptrying = 0;
- } while (keeptrying == 1);
- //printf("%lf", value);
- return value;
- }
- main()
- {
- double a;
- printf(" a = %10.10lf",getdouble(0,100));
- }
Advertisement
Add Comment
Please, Sign In to add comment