fork download
  1. #include <stdio.h>
  2.  
  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. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘maint’:
prog.c:13:10: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[50]’ [-Wformat=]
  scanf("%s", &userName);
         ~^   ~~~~~~~~~
prog.c:21:22: error: ‘DRINKING_AGE’ undeclared (first use in this function)
    userName, curAge, DRINKING_AGE, noYears);
                      ^~~~~~~~~~~~
prog.c:21:22: note: each undeclared identifier is reported only once for each function it appears in
prog.c: In function ‘calcYear’:
prog.c:28:9: error: ‘DRINKING_AGE’ undeclared (first use in this function)
  return(DRINKING_AGE-curAge);
         ^~~~~~~~~~~~
prog.c: In function ‘maint’:
prog.c:13:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", &userName);
  ^~~~~~~~~~~~~~~~~~~~~~
prog.c:15:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %d", &curAge);
  ^~~~~~~~~~~~~~~~~~~~~
prog.c: In function ‘calcYear’:
prog.c:29:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty