time.h

I want a loop to end in a specified number of minutes
[code]
cout << endl << "Enter the length of time (in minutes) you want this program to run: ";
cin >> GetTime;
GetTime = GetTime * 360;
time_t CurrentTime = ( time( NULL ) / 360 );
int StopTime = int(CurrentTime) + GetTime;

while (1)
{
time_t CurrentTime = ( time( NULL ) / 360 );
if ( int(CurrentTime) >= StopTime ) { break; }
}
[/code]
In the "while" loop I put "cout << CurrentTime", and I noticed that the time never even changes, even when I restart the program. What's up with this?

Comments

  • : I want a loop to end in a specified number of minutes
    : [code]:
    : cout << endl << "Enter the length of time (in minutes) you want this program to run: ";
    : cin >> GetTime;
    : GetTime = GetTime * 360;
    : time_t CurrentTime = ( time( NULL ) / 360 );
    : int StopTime = int(CurrentTime) + GetTime;
    :
    : while (1)
    : {
    : [color=Blue]time_t CurrentTime = ( time( NULL ) / 360 );[/color]
    : if ( [color=Blue]int(CurrentTime)[/color] >= StopTime ) { break; }
    : }
    : [/code]:
    : In the "while" loop I put "cout << CurrentTime", and I noticed that
    : the time never even changes, even when I restart the program.
    : What's up with this?
    :

    First off, your redefining CurrentTime inside the loop. You've already defined it outside the loop, so remove 'time_t' from that line to use the existing definition.

    Then the second blue part: Why the int(CurrentTime)? I think it creates a temporary copy of an integer in memory with value from CurrentTime. Just use CurrentTime >= StopTime.
    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion