Phr0zen_Penguin

age.c

Sep 20th, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void main()
  5. {
  6. int age, curryear, birthyear;
  7.   printf ("Enter current year: ");
  8.   scanf ("%d", &curryear);
  9.   printf ("Enter birth year: ");
  10.   scanf ("%d", &birthyear);
  11.  
  12. //if (curryear - birthyear <=20) /*<- if statement was in the wrong place.*/
  13. {
  14.   age = curryear - birthyear; /*NOTE TO SELF: Removing this line yields a very
  15.                               interesting result.*/
  16.   if (curryear - birthyear <=20) /*NOTE TO SELF: Condition following if statement
  17.                                  must always go in parentheses.*/
  18. //  if (age <=20)/*Easier (more appropriate)if statement (*Lvalue over Rvalue)*/
  19.   printf ("\nAge is: %d\n\n", age);
  20. }
  21. system ("pause");
  22. }
Advertisement
Add Comment
Please, Sign In to add comment