fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int i;
  5. float temperature;
  6.  
  7. for (i = 1; i < 4; ++i)
  8. {
  9. printf("Enter a temperature: ");
  10. // Check return value of scanf for robust error handling
  11. if (scanf("%f", &temperature) != 1) {
  12. printf("Invalid input, exiting loop.\n");
  13. break;
  14. }
  15. // Corrected calculation using floating-point division
  16. printf("The temperature converted to Celsius is %8.2f \n", (temperature - 32.0) * (5.0/9.0));
  17. }
  18.  
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0.01s 5280KB
stdin
1
2
3
4
stdout
Enter a temperature: The temperature converted to Celsius is   -17.22 
Enter a temperature: The temperature converted to Celsius is   -16.67 
Enter a temperature: The temperature converted to Celsius is   -16.11