every time i enter a floating point, my program overflows , need to figure out how to test for floating point in while loop, any help is apprecited,,,,
thnx
every time i enter a floating point, my program overflows , need to figure out how to test for floating point in while loop, any help is apprecited,,,,
thnx
It sounds like you have an infinite loop, something like this maybe? :-)
Post your code so I can be sure, it sounds like scanf is choking on a value other than you told it to take.Code:while (scanf("%d", &some_int) != EOF) { /* Do stuff */ }
*Cela*
in the function getnum() when i enter a floating point value it infintley loops, i guess its because my value is declared as int, what i want to do is when they try to use the program and enter a f.p. it says invalid integer, also if someone has an idea on how to implement an array in factor() func that would be awesome,,,
thnx
You avoid it by not using scanf, but if you have to, this is a fix :-)
Code:int GetNum (int num1) { do { printf("Enter a positve real number to be computed\n"); while (scanf("%d", &num1) != 1) { fprintf(stderr, "Invalid input, please try again: "); while (getchar() != '\n') {} /* Clear the bad stuff */ } } while ( num1 <= 0 ); return num1; }
*Cela*
or use fgets() and strtol() to verify the input.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]