How to Make a Clock Project in C++ | Project in C++ using if and else conditions


How to Make a Clock Project in C++ or Project in C++. Hi, My name is Bilal Ahmad and today we will discuss how to make a simple project in c++ and basically, it is very simple and easy to make using if and else condition and a while loop so let start how we will do this.

How to Make a Clock Project in C++  Project in C++
How to Make a Clock Project in C++  Project in C++

If and Else Condition:

if and else condition is used to check which one condition is correct in C++ and in the other languages also. so with the help of this, we will make a Clock Project in C++.

Clock Project in C++:

Clock project will work like when we enter the hours, minutes, and seconds, the clock will start and it will work on its own.

Code of C++ project:


#include<iostream>
#include<Windows.h>
using namespace std;
int main()
{
int hours = 0, seconds = 0, minutes = 0, err = 0, a = 0;
err = a = 0;
while (err == 0)
{
cout << "please enter the hours   :";
cin >> hours;
cout << "please enter the minutes  :";
cin >> minutes;
cout << "please enter the seconds    :";
cin >> seconds;
if (hours < 24 && minutes < 60 && seconds < 60)
{
err++;
}
else
{
system("cls");
}
}
while (a == 0)
{
system("cls");
cout << hours << ":" << minutes << ":" << seconds << endl;
Sleep(1000);
seconds++;
if (seconds > 59)
{
seconds = 0;
minutes++;
}
if (minutes > 59)
{
minutes = 0;
hours++;
}
if (hours > 24)
{
hours = 0;
}
}
system("pause");
return 0;
}

So this is the simple and basic project in c++ using if and else conditions.

Conclusion :
So you can easily understand what happens to this project if you have some knowledge about C++.

Best Regards,
Bilal Ahmad

No comments

Please tell me if you have any suggestions related to these projects.
thanks

Powered by Blogger.