fork download
  1. #include <stdio.h>
  2.  
  3. // Function to convert dog years to human years
  4. float calcDogToHumanYears(int dogYears)
  5. {
  6. float humanYears;
  7. if (dogYears <= 0)
  8. humanYears = 0;
  9. else if (dogYears == 1)
  10. humanYears = 15;
  11. else if (dogYears == 2)
  12. humanYears = 9;
  13. else
  14. humanYears = 24 + ((dogYears - 2) * 5);
  15. return humanYears;
  16. }
  17.  
  18. // Main function to test calcDogToHumanYears
  19. int main(void)
  20. {
  21. int dogYears;
  22. printf("Enter dog's age in years: ");
  23. scanf("%d", &dogYears);
  24.  
  25. float humanYears = calcDogToHumanYears(dogYears);
  26. printf("Equivalent human years: %.2f\n", humanYears);
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Enter dog's age in years: Equivalent human years: 163839.00