Hello guys, how are all you doinbg ? Well I just created this program to cound 24 hours. The
program runs fine but my only problem is when I ran the programs i get the following
0:0:0
4469690:0:1
4469690:0:2
Where is the number 446969 coming from ? I am pretty certain is a dumb answer but I gots to know. Thank you all for your help. Oh the code is here
GCard
#include <iostream>
#include <ios>
#include <istream>
#include <limits>
#include <windows.h>
using namespace std;
template <typename CharT>
void ignore_line ( std::basic_istream<CharT>& in )
{
in.ignore ( std::numeric_limits<std::streamsize>::max(), in.widen ( '\n' ) );
}
class CClock
{
private:
short nHours,nMinutes,nSeconds;
public:
void InitTime(void);
void AdvanceHours(void);
void AdvanceMinutes(void);
void AdvanceSeconds(void);
int OurTimeIs(short,short,short);
};
void CClock::InitTime(void)
{
nHours = 0;
nMinutes=0;
nSeconds=0;
}
void CClock::AdvanceHours(void)
{
nHours++;
if(nHours>23){
nHours=0;
}
}
void CClock::AdvanceMinutes(void)
{
nMinutes++;
if (nMinutes>59){
nMinutes=0;
}
}
void CClock::AdvanceSeconds(void)
{
nSeconds++;
if (nSeconds>59){
nSeconds=0;
}
}
int CClock::OurTimeIs(short a, short b, short c)
{
a = nHours;
b = nMinutes;
c = nSeconds;
cout << a << ":" << b << ":" << c << "\n";
}
int main()
{
CClock clock;
clock.InitTime();
for(short h=0;h<24;h++){
for(short m=0;m<60;m++){
for(short s=0;s<60;s++){
cout << clock.OurTimeIs(h,m,s);
Sleep(1000);
clock.AdvanceSeconds();
}
clock.AdvanceMinutes();}
clock.AdvanceHours();}
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n') ;
ignore_line ( std::cin );
return 0;
}