Timer and other problems...

Pages: 12
maybe you should listen to coder777 and me and use seconds and a for loop.
if you still want to print the minutes and hours, you can use the modulo operator "%"
Im sorry... i do not know anything about anything of what you said.... still learnin'
look at this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
int amount_sec = 0;
	if (secminhour=="seconds")
	{
		amount_sec = amount;
	}
	else if (secminhour=="minutes")
	{
		amount_sec = amount * 60;
	}
	else if (secminhour=="hours")
	{
		amount_sec = amount * 60 * 60;
	}
	else
	{
		cout<<"ERROR!";
	}

	for(int i = 0; i < amount_sec; ++i)
	{
		cout<<hours<<":"<<minutes<<":"<<seconds<<endl;
		seconds=seconds+1;
		if (seconds==60)
		{
			seconds=0;
			minutes=minutes+1;
		}
		if (minutes==60)
		{
			minutes=0;
			hours=hours+1;
		}
		Sleep(1000);
	}
Will someone translate into english please :D add some comments or something
what excactly do you not understand?

maybe this helps you http://www.cplusplus.com/doc/tutorial/control/

scroll down till you reach loops
Last edited on
What i do not understand:
for loop
modulo operator %


i give up... ill take an easier task...
you do not need the modulo operator %

the for loop can be expressed as a while loop:
This
for(int i = 0; i < amount_sec; ++i)

can be replaced with this:
1
2
3
4
5
6
int sec = 0;
while( sec < amount_sec)
{
...
sec = sec + 1;
}

As you can see: the for loop is just a convenient syntax

i give up
if you give up that quick you won't get far...
Last edited on
if you have problems with the loops. try to set up an 10 elements array and print each element with a for, a while and a do while loop.
it will give you an idea how to change them to receive the same result.

the mudulo operator returns the rest of an integer division
so 5 % 2 is 1, since 5 - (2*2) = 1
the problem is, im 13 years old and my native language is not english so im having problems learning stuff in english...
Topic archived. No new replies allowed.
Pages: 12