Hello, i have learned a bit more about ctime and loops.
If any of you needed a digital clock code. Here it is if not then it's okay, because i know this script is for beginners.
Here's a way to do it:
Code:#include <iostream> #include <windows.h> int main() { using namespace std; int minutes = 0; // set the minutes int hours = 5; //set the hour Loop: for (int a = 0; a < 61; a++) { if (a == 60) { minutes = minutes + 1; a = a - 60; goto Loop; } if (minutes == 60) { hours = hours + 1; minutes = 0; goto Loop; } if (hours == 13) { hours = hours - hours; hours = hours + 1; } system("cls"); cout <<"Hours:"<<hours<<"/ Minutes:"<<minutes<<"/ Seconds:"<<a; Sleep(1000); } cin.get(); return 0; }
This way will just help you learn more about loops and how digital clocks loops works.
Here's a more useful way to do it, to set the time to your computer time.
Thank you, hope you find it useful, actually, for the people who just started c++.Code:#include <ctime> #include <iostream> #include <windows.h> int main() { using std::cin; bool loop = true; while (loop) { std::time_t now = std::time ( 0 ); std::tm *local = std::localtime ( &now ); local->tm_hour -= 6; system("cls"); std::cout << ctime ( &now ) <<'\n'; Sleep(1000); } cin.get(); return 0; }



LinkBack URL
About LinkBacks



