fork download
  1. #include <stdio.h>
  2. #define DRINKING_AGE 21
  3. int curAge, noYears;
  4.  
  5. int calcYear(int curAge);
  6.  
  7. int main(void)
  8. {
  9. //Local Variables
  10. char userName[50];
  11. //Ask the suer for name and birth year
  12. printf("Enter your name: ");
  13. scanf("%s", &userName);
  14. printf("Enter your current age: ");
  15. scanf(" %d", &curAge);
  16.  
  17. //Call the function to calculate the
  18. noYears = calcYear(curAge);
  19.  
  20. printf("%s is %d years old and will be %d in %d years.",
  21. userName, curAge, DRINKING_AGE, noYears);
  22. return 0;
  23. }
  24.  
  25. /* The function to get the future year */
  26. int calcYear(int curAge)
  27. {
  28. return(DRINKING_AGE-curAge);
  29. }
  30.  
Success #stdin #stdout 0s 4508KB
stdin
Standard input is empty
stdout
Enter your name: Enter your current age:  is 0 years old and will be 21 in 21 years.