Skip to content

Instantly share code, notes, and snippets.

@SemanticallyNull
Created November 6, 2011 13:38
Show Gist options
  • Save SemanticallyNull/1342888 to your computer and use it in GitHub Desktop.
Save SemanticallyNull/1342888 to your computer and use it in GitHub Desktop.
Finally began messing around with C... much is coming back to me now, and realising how little I know.
#include <stdio.h>
int main(void) { // Thanks to @barrettcolin for showing me the way.
int age;
printf("What is your age? ");
scanf("%d", &age); // Accept a numeric input and push it to age (by getting the lvalue of age)
if(age < 5) {
printf("Wow, you're very young!\n");
} else if(age < 12) {
printf("Oh, older now!\n");
} else if(age < 18) {
printf("A teenager? Party everyday!\n");
} else {
printf("Sorry, you're an adult now. Parties with beer (and whiskey)!\n");
}
return 0; // Oops, forgot this originally. Though as it turns out there was no need to do this at all in C99
} // Also forgot the newline at the end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment