i'm a beginner to programming and got an assignment to create a stopwatch/timer, that counts in seconds/minutes/days etc
Does anybody know a way to create a timer through classes, functions and loops without using the clock function or whatever?
So far I managed to create a class for seconds and a bit of a function but it still doesn't count and when i try add the loop the build crashes (see below) and when i try put it in the function it also crashes. any help would be great, thanks
using namespace std;
seconds = 0;
minutes = 0;
hours = 0;
days = 0;
months = 0;
years = 0;
for(int i=1, i<60, i++)
cout << i << endl;
It's impossible. You need to use some kind of gettick or clock function. There is no way to tell how much time has passed otherwise.
Simply spinning in a loop will not tell you anything, because it's subject to how fast the computer is and how much cpu time your program is getting. Not to mention it consumes (wastes) lots of cpu time to do that.