/* A program to test consistency-checking of user inputs. Asks for a non-negative mass, and repeatedly complains until it gets one. Then it prints the final value back out again as a check. */ #include main () { float mass_in_kilos; /* Ask the user for a non-negative mass in kilograms. */ printf("What is the mass in kilograms? "); /* Input the answer. */ scanf("%f", &mass_in_kilos); /* while the answer is negative: */ while (mass_in_kilos < 0.0) { /* Explain the error and ask for another value. */ printf("Sorry, masses cannot be negative. Please re-enter: "); /* Input another mass value. */ scanf("%f", &mass_in_kilos); } /* Print the mass back as a check. */ printf("The mass is %f kg.\n", mass_in_kilos); }