Odliczanie dwóch czasów w tym samym momencie
Ostatnio zmodyfikowano 2017-08-04 10:29
polakpl Temat założony przez niniejszego użytkownika |
Odliczanie dwóch czasów w tym samym momencie » 2017-08-03 23:05:06 Chcę zrobić program, który będzie odliczał 2 czasy na raz. Na przykład wciskam enter i konsola pokazuje, że minęło 35 minut i w tym samym czasie mogę uruchomić kolejny licznik naciskając enter. I w tym miejscu utknąłem. Na razie mam tyle #include <iostream> #include <time.h> #include <windows.h> #include <cstdlib> #include <cstdio> #include <conio.h>
using namespace std; int x; int main() { cout << "Odlicz 100 minut w tle" << endl; getchar(); for( int i = 1; i <= 6000; i++ ) { x = i / 60; system( "cls" ); cout << "Minelo " << x << " minut" << endl; cout << "Odlicz 20 minut" << endl; Sleep( 100 ); } return 0; }
Jest możliwość działania dwóch pętli na raz? Coś w stylu for(int i=1; i<=6000; i++)&&(int j=1; j<=1500; j++), ale to niestety nie działa. Chciałbym żeby to wyglądało mniej więcej tak: Minęło 13 minut Odlicz 20 minut *kliknięcie entera* Minęło 13 minut Minęło 0 minut *po 10 minutach* Minęło 23 minut Minęło 10 minut itd. |
|
pekfos |
» 2017-08-03 23:13:36 Wątki. |
|
polakpl Temat założony przez niniejszego użytkownika |
Wątki » 2017-08-03 23:34:15 Programuję w codeblocks i nie mam tu biblioteki z wątkami, więc pokombinowałem ze switchem, o to co wykombinowałem: #include <iostream> #include <time.h> #include <windows.h> #include <cstdlib> #include <cstdio> #include <conio.h>
using namespace std; int x, y; char wybor; int main() { { cout << "Odlicz 100 minut w tle" << endl; getchar(); for( int i = 1; i <= 6000; i++ ) { x = i / 60; system( "cls" ); cout << "Minelo " << x << " minut" << endl; cout << "Wpisz 1 aby odliczyc 20 minut" << endl; wybor = getch(); switch( wybor ) { case '1': for( int j = 1; j <= 1200; j++ ) { x = i / 60; y = j / 60; system( "cls" ); cout << "Minelo " << x << " minut" << endl; cout << "Minelo " << y << " minut" << endl; i++; Sleep( 1 ); } break; Sleep( 1 ); } } return 0; } }
da się to jakoś poprawić bo raczej nie jest tak jak być powinno? Trzeba wciskać enter żeby sekundy mijały |
|
Kinexity |
» 2017-08-03 23:42:11 Ludzie sprawdzajcie czasami co wstawiacie - funkcja getch() zwraca KOD KLAWISZA, a nie ZNAK
Edit: No nie mów że CB nie ma <thread>... |
|
polakpl Temat założony przez niniejszego użytkownika |
» 2017-08-03 23:46:27 kiedy dodaję bibliotekę thread i wciskam F9 to pokazuje mi się coś takiego: // Copyright (C) 2007-2014 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version.
// This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>.
/** @file bits/c++0x_warning.h * This is an internal header file, included by other library headers. * Do not attempt to use it directly. @headername{iosfwd} */
#ifndef _CXX0X_WARNING_H #define _CXX0X_WARNING_H 1
#if __cplusplus < 201103L #error This file requires compiler and library support for the \ ISO C++ 2011 standard. This support is currently experimental, and must be \ enabled with the -std=c++11 or -std=gnu++11 compiler options. #endif
#endif |
|
Kinexity |
» 2017-08-03 23:48:32 No to w opcjach kompilatora włącz obsługę C++11 EDIT; Tak wgl to jeżeli dobrze rozumiem twój problem to zamiast używać wątków to chyba wystarczy zapisywać momenty rozpoczęcia odliczania i na podstawie nich ustalać czas pozostały do końca |
|
pekfos |
» 2017-08-03 23:51:37 Ludzie sprawdzajcie czasami co wstawiacie - funkcja getch() zwraca KOD KLAWISZA, a nie ZNAK |
A to od kiedy? |
|
Kinexity |
» 2017-08-03 23:54:26 No a tak nie jest? Wiesz gdzieś tutaj (cpp0x.pl) takie coś przeczytałem... |
|
« 1 » 2 |