-Pie Day Countdown Timer-

by Aluminum_Australia in Design > Software

63 Views, 1 Favorites, 0 Comments

-Pie Day Countdown Timer-

pie final.png
Pie count.png

For this Instructable, I wanted to do something interactive that other people can use. The reason I decided to write code and not do something physical is because I have recently started learning C++ code, and when my friend showed me this website, I decided to enter this contest to see if I could win with my new coding skills. I also wanted to challenge myself by making something that updates in real time and uses logic instead of being a physical build. I chose a Pi Day countdown because it was a fun way to practice working with dates, loops, and time calculations in C++. It also helped me understand how programs can use the system clock to create something that changes every second. This project showed me how coding can be used to make simple but interesting tools that people can actually use. Overall, I enjoyed making this because it helped me learn more about programming while building something creative at the same time.


Supplies

pie code.png

This is the code for my project if anyone wants to run it. This is C++ code:


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <ctime>
#include <thread>

using namespace std;

time_t getNextPiDay() {
time_t now = time(0);
tm* ltm = localtime(&now);

int year = 1900 + ltm->tm_year;

tm piDay = {};
piDay.tm_year = year - 1900;
piDay.tm_mon = 2;
piDay.tm_mday = 14;
piDay.tm_hour = 0;
piDay.tm_min = 0;
piDay.tm_sec = 0;

time_t piTime = mktime(&piDay);

if (difftime(piTime, now) <= 0) {
piDay.tm_year += 1;
piTime = mktime(&piDay);
}

return piTime;
}

int main() {
// Title shown once at the top
cout << "==============================\n";
cout << " PIE DAY COUNTDOWN \n";
cout << "==============================\n\n";

while (true) {
time_t now = time(0);
time_t piDay = getNextPiDay();

long long diff = static_cast<long long>(difftime(piDay, now));

int days = diff / 86400;
int hours = (diff % 86400) / 3600;
int minutes = (diff % 3600) / 60;
int seconds = diff % 60;

cout << "\r"
<< days << "d "
<< hours << "h "
<< minutes << "m "
<< seconds << "s remaining " << flush;

this_thread::sleep_for(chrono::seconds(1));
}
}

Planning the Project

I started by deciding what I wanted to build for this project. I chose to make a Pi Day countdown because it is simple, fun, and uses real-time updates. I also planned how the program would need to calculate the time left until March 14.

Writing the Code

Screenshot 2026-04-23 132008.png

Next, I wrote the program in C++ using Visual Studio. I used functions to get the current date and calculate the difference between today and Pi Day. I also added a loop so the countdown updates every second.

Testing and Fixing Errors

failed pie.png

After writing the code, I built and ran the program to test it. I fixed errors related to time calculations and project settings until it worked correctly. Once everything ran smoothly, the countdown displayed correctly in the console.