Alright, so, after messing around with Dev-C++, I've managed to come up with a simple clock:
So, it works all fine and dandy, but I'd like to know what could be improved.Code:#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
unsigned short int hours = 0;
unsigned short int minutes = 0;
unsigned short int seconds = 0;
unsigned short int exit = 0;
string input;
cout<<"Display seconds?\nY/N: ";
cin>>input;
cin.ignore();
cout<<"\n\nPlease set the time (hours)\nTime: ";
cin>>hours;
cin.ignore();
cout<<"\n\nPlease set the time (minutes)\nTime: ";
cin>>minutes;
cin.ignore();
while (exit == 0)
{
system("cls");
if (input == "y")
{
if (minutes < 10)
{
if (seconds < 10)
{
cout<<"\n\nCurrent time: "<<hours<<":0"<<minutes<<":0"<<seconds;
}
else
{
cout<<"\n\nCurrent time: "<<hours<<":0"<<minutes<<":"<<seconds;
}
}
else
{
if (seconds < 10)
{
cout<<"\n\nCurrent time: "<<hours<<":"<<minutes<<":0"<<seconds;
}
else
{
cout<<"\n\nCurrent time: "<<hours<<":"<<minutes<<":"<<seconds;
}
}
if (seconds >= 60)
{
minutes++;
seconds = 0;
}
if (minutes >= 60)
{
hours++;
minutes = 0;
seconds = 0;
}
if (hours >= 13)
{
hours = 1;
minutes = 0;
seconds = 0;
}
seconds++;
Sleep (1000);
}
if (input == "n")
{
if (minutes < 10)
{
cout<<"\n\nCurrent time: "<<hours<<":0"<<minutes;
}
else
{
cout<<"\n\nCurrent time: "<<hours<<":"<<minutes;
}
if (seconds >= 60)
{
minutes++;
seconds = 0;
}
if (minutes >= 60)
{
hours++;
minutes = 0;
seconds = 0;
}
if (hours >= 13)
{
hours = 1;
minutes = 0;
seconds = 0;
}
seconds++;
Sleep (1000);
}
}
return 0;
}
(also, is it possible to preformat integers to show 01 instead of 1?)
And yes, I'm definitely not very far along, but writing simple applications amuses me :P
What I'm asking is what would somebody more experienced do differently to achieve the same purpose?