473,383 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

The timer is not stopping

Hello my problem in this program is that it dose not stop at 0 it also goes to negative numbers please someone fix this

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4. void newline();
  5. using namespace std;
  6. int main()
  7. {
  8.     int hours = 0;
  9.     int minutes = 0;
  10.     int seconds = 0;
  11.     cout<< "Please enter houres: ";
  12.     cin>>hours;
  13.     cout<< "Enter a minutes: ";
  14.     cin>>minutes;
  15.     cout<<"Enter seconds: ";
  16.     cin>>seconds;
  17.     for(;;){
  18.             newline();
  19.  
  20. cout<< hours <<" : "<< minutes <<" : "<< seconds << endl;
  21. Sleep(750);
  22.             --seconds;
  23.             if(seconds == 0){
  24.             --minutes;
  25.             seconds = 60;
  26.             }
  27.             if ( minutes == 0){
  28.                    -- hours;
  29.                    minutes = 0 ;
  30.                    }
  31.             if ( hours == 0){
  32.                  hours = 0;
  33.                 }                 
  34.  
  35.                  }
  36.  
  37. return 0;
  38. }               
  39. void newline(){
  40.      cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
  41.      }                               
  42.  
Feb 1 '14 #1
3 1243
This is a c++ program
Feb 1 '14 #2
weaknessforcats
9,208 Expert Mod 8TB
There's no exit to your for loop.

Note also that --minutes will produce -1 minutes if minutes was zero to start with.

I suspect you want to stop your timer if
(hours && minutes && seconds) == 0
but I don't see code like that in the loop:
Feb 1 '14 #3
donbock
2,426 Expert 2GB
Line 29: probably want to set minutes to 60.
Line 32:this doesn't accomplish anything.
Lines 11-16: you should validate the inputs.
Feb 1 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Geoff | last post by:
Hey.. I'm having problems with stopping this timer from outside the 'runTimer()' class.. i have no problems calling 'cancel()' from inside the run() method but I want to be able to stop the Timer...
3
by: ray | last post by:
Hi, I just wrote a windows service application to call a function of another object periodically. I used System.Server.Timer and I found that it works fine within the first 2 hours but the...
4
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group :...
5
by: Mike P | last post by:
With the VB6 timer, it was simply a matter of setting Enabled = true to start the timer, and Enabled = false to stop the timer. With C# you also have Start and Stop methods. To get the same...
3
by: chrisdevey | last post by:
Is there any way to make a System.Timers.Timer adjust for daylight savings time change? In a long running process I set a timer as follows for a daily expiration: _myTimer = new...
3
by: Scott H | last post by:
Hello, I'm having a go at writing my first Windows Service in VB.NET and I'm having a problem. I have it installed ok and started the service sucessfully, I can stop it, and restart it fine, the...
12
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different...
8
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have...
4
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have a main thread an another worker thread. The main Thread creates another thread and waits for the threads signal to continue the main thread. Everything works inside a ModalDialog and...
2
by: tawanda diza | last post by:
hie all. i am new to c#, ma y you please help me on how to stop a timer. i created a timer during design time. i am looking at some sources here and they say i must use timer.stop(); but when...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.