user:asowers:fun_with_time
Table of Contents
Welcome
It's possible to create simple games with the time.h header file.
Time for fun
Students from college campuses across America are familure with the game “Power Hour.”(Google is your friend) The game entails preforming a certain action every minute for one hour. Using C programming, this task can be automated. Automation in this instance allows people more time to socialize by taking away the time needed to moderate the game.
code
#include <stdio.h> #include <time.h> int main() { printf("Begin power hour!\n\a"); int i; for(i = 0; i <= 60; ++i) { printf("Minute Number: %d\n",i); sleep(60); printf("Drink!\n\a"); } printf("Congratulations, you've survived power hour!"); return 0; }
Compilation and execution:
andrew ~/src $ gcc powerhour.c -o powerhour andrew ~/src $ ./powerhour Begin power hour! Minute Number: 0 Drink! Minute Number: 1 Drink! Minute Number: 2 (etc)
Final thoughts
Programming is about more than solving mundane problems; it's also about improving peoples quality of life through simplex enhancements.
user/asowers/fun_with_time.txt · Last modified: 2012/12/03 13:10 by asowers