problem with counter

T

Test3456

Hello,

i got following Job:
Write a programm that shows the letters a - z. The lettes should be
act in some millisecounds. Start with 100 millisecounds and every loop
the millisecounds show be rise of 10 percent (such as the secound loop
110, the third 121...)

First Time i thougt this.

execute the loop until the actual time is bigger then the pause (100
millisecounds).

But it doesent work.

I hope you can help me

Regards

Sebastian

=== German Version ===

Hallo,

ich habe folgende Aufgabe bekommen.

Schreibe ein programm das die Zahlen 1 bis 100 ausgibt. Die Zahlen
sollen nacheinander erscheinen aber in unterschiedlichen
Zeitabständen. Beginne mit 100 Ms und steigere in jeder runde die
Millisekunden um 10 Prozent.


Wie soll ich das in der console machen? ich kann mir mit clock die
aktuelle uhrzeit holen, "Startzeit" messen- Schleife solange
ausführen bis "aktuelle Zeit" - "Startzeit" >= "Pause". Das ist ja
soweit klar, aber wie soll ich das programmieren?

Ich blicke da nicth so durch.

Bitte erklärt es mir

Gruß

Sebastian
 
S

Stuart Redmann

Test3456 said:
Hello,

i got following Job:
Write a programm that shows the letters a - z. The lettes should be
act in some millisecounds. Start with 100 millisecounds and every loop
the millisecounds show be rise of 10 percent (such as the secound loop
110, the third 121...)
First Time i thougt this.

execute the loop until the actual time is bigger then the pause (100
millisecounds).

AFAIK, there is no platform-independent way of doing this. Under Windows
look up the Sleep (DWORD Milliseconds) function.

Regards,
Stuart
 
L

Lionel B

Hello,

i got following Job:
Write a programm that shows the letters a - z. The lettes should be
act in some millisecounds. Start with 100 millisecounds and every loop
the millisecounds show be rise of 10 percent (such as the secound loop
110, the third 121...)

First Time i thougt this.

execute the loop until the actual time is bigger then the pause (100
millisecounds).

But it doesent work.

That doesn't really help anyone solve your problem. Post some (preferably
compilable) code showing what you have tried so far, and explain what you
mean by "doesn't work".

[...]
 
T

Test3456

i got following Job:
Write a programm that shows the letters a - z. The lettes should be
act in some millisecounds. Start with 100 millisecounds and every loop
the millisecounds show be rise of 10 percent (such as the secound loop
110, the third 121...)
First Time i thougt this.
execute the loop until the actual time is bigger then the pause (100
millisecounds).
But it doesent work.

That doesn't really help anyone solve your problem. Post some (preferably
compilable) code showing what you have tried so far, and explain what you
mean by "doesn't work".

[...]

#include <iostream>
#include <ctime>

const unsigned short count_numbers = 100;

int main()
{
std::wcout << L"Wellcome to Clock-Counter V0.1" << std::endl;

clock_t time_start = clock();

for (unsigned short number = 1; number <= count_numbers; ++number)
{
while ((clock() - time_start) > (number * 10)); // Jetzt
wird gewartet, bis die
//
Differenz von vorher und jetzt
// gleich
(number * 10) ist ...
// TODO:
Gewünschte Zeit einsetzen.

std::wcout << number << std::endl; // Zahl
ausgeben ...
}

return 0;
}

This is my code, which i have at the moment, but it doesent seam to
work. I hope you dont understand my explanation right.

The First Number should be appear 1 secound or 1000 ms. but i dont
know why this code doesnt work.

I tryed to solve the problem 4 hours but i cannot find this error :-(
 
S

Stuart Redmann

#include <iostream>
#include <ctime>

const unsigned short count_numbers = 100;

int main()
{
std::wcout << L"Wellcome to Clock-Counter V0.1" << std::endl;

clock_t time_start = clock();

You only take the start time once. I think you actually want to take the
start time each time you're going to wait for the next number.
for (unsigned short number = 1; number <= count_numbers; ++number)
{
while ((clock() - time_start) > (number * 10));

This condition will never be true since the time taken at the call of
clock will be very close to time_start, so that clock() - time_start is
almost always smaller than number * 10. Thus the while loop will exit at
the first iteration (so that it won't "eat away" any time at all).
> std::wcout << number << std::endl;
}

return 0;
}
This is my code, which i have at the moment, but it doesent seam to
work. I hope you dont understand my explanation right.

The First Number should be appear 1 secound or 1000 ms. but i dont
know why this code doesnt work.

I tryed to solve the problem 4 hours but i cannot find this error :-(

You should inflate the code so that you can run it through a debugger
(by inflating I mean that you should expand the while loop so that you
can see how many times it runs). Cutting down the code to a point where
you have solved the problem with the minimum amount of code will get you
to a point where you spend the maximum amount of time debugging.

Regards,
Stuart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top