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;
}

OurTimeIs() has the parameters for the desired hours, minutes, and seconds. So why is it resetting those times to those of the class? What good are the parameters then? If that's what you want, then delete the parameters and use the class time variables directly. If not, then delete lines 62, 63 and 64.

line 12 and 83: produces a compile error. I compiled your program with VC++ 2008 Express. This is probably the cause of your problem -- you must have just ignored this error.

OurTimeIs() has the parameters for the desired hours, minutes, and seconds. So why is it resetting those times to those of the class? What good are the parameters then? If that's what you want, then delete the parameters and use the class time variables directly. If not, then delete lines 62, 63 and 64.

line 12 and 83: produces a compile error. I compiled your program with VC++ 2008 Express. This is probably the cause of your problem -- you must have just ignored this error.

I am compiling with Dev C++ since is the only program I could get for free. But when I compile it it runs fine and it doesn't even give me any warnings, then I still don't understand why the numbers appear. it should be

0:0:0
0:0:1
0:0:2

and so forht unitl it reaches 23:59:59 GCard

Here's the compiler output from VS (is also free):

Warning 1 warning C4003: not enough actual parameters for macro 'max' c:\Documents and Settings\Niekd\Mijn documenten\Visual Studio 2005\Projects\dani\dani\dani.cpp 17
Warning 2 warning C4003: not enough actual parameters for macro 'max' c:\Documents and Settings\Niekd\Mijn documenten\Visual Studio 2005\Projects\dani\dani\dani.cpp 90
Error 3 error C2589: '(' : illegal token on right side of '::' c:\Documents and Settings\Niekd\Mijn documenten\Visual Studio 2005\Projects\dani\dani\dani.cpp 90
Error 4 error C2143: syntax error : missing ')' before '::' c:\Documents and Settings\Niekd\Mijn documenten\Visual Studio 2005\Projects\dani\dani\dani.cpp 90
Error 5 error C2059: syntax error : ')' c:\Documents and Settings\Niekd\Mijn documenten\Visual Studio 2005\Projects\dani\dani\dani.cpp 90

Dev-C++ doesn't produce the errors that VC++ 2008 Express does. The problem with the program is that line 79 is printing the return value of clock.OurTimeIs(), but that function isn't returning anything, so the return value is just some random number. Dev-C++ should have produced a warning or error about that, but it didn't.

Dev-C++ doesn't produce the errors that VC++ 2008 Express does. The problem with the program is that line 79 is printing the return value of clock.OurTimeIs(), but that function isn't returning anything, so the return value is just some random number. Dev-C++ should have produced a warning or error about that, but it didn't.

Ok I downloaded Visual. I understand now what you meant by return value. If uses as a void I still get an error

Compiling...
times.cpp
.\times.cpp(78) : error C3867: 'CClock::OurTimeIs': function call missing argument list; use '&CClock::OurTimeIs' to create a pointer to member

when I change

int CClock::OurTimeIs(short a, short b, short c)
{
    a = nHours;
    b = nMinutes;
    c = nSeconds;
    cout << a << ":" << b << ":" << c << "\n";
}

to

void CClock::OurTimeIs(short a, short b, short c)
{
    a = nHours;
    b = nMinutes;
    c = nSeconds;
    cout << a << ":" << b << ":" << c << "\n";
}

I am so new with C++ and pointers are a still a skill to be acquired. Can you help.

GCard

Ok I downloaded Visual. I understand now what you meant by return value. If uses as a void I still get an error

Compiling...
times.cpp
.\times.cpp(78) : error C3867: 'CClock::OurTimeIs': function call missing argument list; use '&CClock::OurTimeIs' to create a pointer to member

when I change

int CClock::OurTimeIs(short a, short b, short c)
{
    a = nHours;
    b = nMinutes;
    c = nSeconds;
    cout << a << ":" << b << ":" << c << "\n";
}

to

void CClock::OurTimeIs(short a, short b, short c)
{
    a = nHours;
    b = nMinutes;
    c = nSeconds;
    cout << a << ":" << b << ":" << c << "\n";
}

I am so new with C++ and pointers are a still a skill to be acquired. Can you help.

GCard

Sorry I just realized where I was wring, I forgot to add the data needed for OurTimeIs to work. Thank you for your help

GCard

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.