Any improvements i can make? thanks still a newbie

+1 Aadesh Rana · January 29, 2015

//initialazing time to 0
stopwatch::stopwatch()
{
   mTime=0;
   sTime=0;
   hTime=0;
}
//displaying the time
void stopwatch::displayTime(){
cout<<hTime<<":"<<mTime<<":"<<sTime<<endl;
Sleep(600);
system("cls");

}
//for seconds
void stopwatch::secondsTime(){
for(sTime=0;sTime<61;++sTime){
displayTime();
if(sTime==60)
minuteTime();
}
}
//for minute
void stopwatch::minuteTime(){
if(mTime!=61){
mTime++;
displayTime();
secondsTime();
}
else
hourTime();
}
//for hour
void stopwatch::hourTime(){
mTime=0;
hTime++;
displayTime();
secondsTime();
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Aadesh Rana · January 29, 2015

#ifndef STOPWATCH_H
#define STOPWATCH_H
#include<iostream>

class stopwatch
{
    public:
        stopwatch();
        void secondsTime();
        void minuteTime();
        void displayTime();
        void hourTime();
    protected:
    private:
        int mTime;
        int sTime;
        int hTime;
};

well thats my whole program with off course the main function calling the secondsTime, and yea i had my programs tabbed copy paste f*cked it. What might you be scared of? 
+2 Jake Scaife · January 29, 2015
Please... Use more whitespace.
For example:
for (sTime = 0; sTime < 61; ++sTime)
{
   displayTime();
   
   if (sTime == 60){
      minuteTime();
   }
}


Just helps improve readability..

There are some other things which scare me, but since it seems like you haven't included all the code - and if the program compiles - I guess its fine
  • 1

C++

107,007 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator