#include <stdio.h>
int main(void)
{
float change;
do
{
printf("Change: ");
}while(scanf("%f", &change) == 0);
printf("Good");
}
Asked
Active
Viewed 36 times
1

pmg
- 106,608
- 13
- 126
- 198

carlkaziboni
- 11
- 1
-
1You can be stuck in an infinite loop if the user types, for example, "forty two
". Better use `fgets()` for user input. You can follow `fgets()` with `strtod()`... – pmg Jan 08 '22 at 12:13 -
Begin by reading *strings* (actually full lines) and then attempt to parse it as a number (using e.g. `strtod`). – Some programmer dude Jan 08 '22 at 12:24
-
Follow the approach of using `fgets`, https://stackoverflow.com/q/26583717/14973743 – Anand Sowmithiran Jan 08 '22 at 13:44
-
Does this answer your question? [How to scanf only integer?](https://stackoverflow.com/questions/26583717/how-to-scanf-only-integer) – Adrian Mole Jan 16 '22 at 13:22