котвася
07-08-2010, 21:52
вот написал таймер, ток не могу придумать как остановить.
Помогите.
//STOPWATCH.CPP
//Снкундомер в консоли.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
using std::setw;
#include <time.h>
void wait(int seconds)
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while ((clock() < endwait)) {}
}
void printStopWatch(int seconds = 0, int status = 0)
{
char *ptr[10] = {"СЕКУНДОМЕР", "РАБОТАЕТ", "CТОП"};
cout << "********************" << endl;
cout << "********************" << endl;
cout << "| " << setw(10) << *(ptr+status) << " |" << endl;
cout << "| " << setw(2) << seconds/60 << " : "
<< setw(2) << ((seconds < 60) ? seconds : seconds%60) << " |" << endl;
cout << "********************" << endl;
cout << "********************" << endl;
}
int main()
{
setlocale(LC_ALL, ".1251");
cout << "Приложение секундомер" << endl;
int n = 0;
bool status = true;
printStopWatch(0,0);
cout << "Нажмите клавишу Enter для начала...";
cin.get();
while(status != false)
{
system("cls");
printStopWatch(n,1);
wait (1);
n++;
}
printStopWatch(n, 3);
return 0;
}
Помогите.
//STOPWATCH.CPP
//Снкундомер в консоли.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
using std::setw;
#include <time.h>
void wait(int seconds)
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while ((clock() < endwait)) {}
}
void printStopWatch(int seconds = 0, int status = 0)
{
char *ptr[10] = {"СЕКУНДОМЕР", "РАБОТАЕТ", "CТОП"};
cout << "********************" << endl;
cout << "********************" << endl;
cout << "| " << setw(10) << *(ptr+status) << " |" << endl;
cout << "| " << setw(2) << seconds/60 << " : "
<< setw(2) << ((seconds < 60) ? seconds : seconds%60) << " |" << endl;
cout << "********************" << endl;
cout << "********************" << endl;
}
int main()
{
setlocale(LC_ALL, ".1251");
cout << "Приложение секундомер" << endl;
int n = 0;
bool status = true;
printStopWatch(0,0);
cout << "Нажмите клавишу Enter для начала...";
cin.get();
while(status != false)
{
system("cls");
printStopWatch(n,1);
wait (1);
n++;
}
printStopWatch(n, 3);
return 0;
}