返回列表 發帖

數秒計時器

本帖最後由 tonyh 於 2014-6-14 17:34 編輯

設計一程式, 讓使用者能指定秒數, 執行畫面如下:





  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     re:
  8.     int sec;
  9.     double c1, c2;
  10.     int c;
  11.     cout<<"請輸入要數的秒數: ";
  12.     cin>>sec;
  13.     c1=clock();
  14.     while(true)
  15.     {
  16.          c2=clock();
  17.          c=(c2-c1)/1000;      
  18.          cout<<(c2-c1)/1000<<"秒!";
  19.          system("cls");
  20.          if(c==sec)
  21.               break;  
  22.     }
  23.     cout<<"時間到! 共經過了"<<sec<<"秒!"<<endl;
  24.     system("pause");
  25.     system("cls");
  26.     goto re;     
  27.     return 0;   
  28. }
複製代碼
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     re:
  8.     int sec;
  9.     double c1, c2;
  10.     int c;
  11.     cout<<"請輸入要數的秒數: ";
  12.     cin>>sec;
  13.     c1=clock();
  14.     while(c!=sec)
  15.     {
  16.          c2=clock();
  17.          c=(c2-c1)/1000;      
  18.          cout<<(c2-c1)/1000<<"秒!";
  19.          system("cls");
  20.     }
  21.     cout<<"時間到! 共經過了"<<sec<<"秒!"<<endl;
  22.     system("pause");
  23.     system("cls");
  24.     goto re;     
  25.     return 0;   
  26. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     re:
  8.     int sec;
  9.     double c1, c2;
  10.     int c;
  11.     cout<<"請輸入要數的秒數: ";
  12.     cin>>sec;
  13.     c1=clock();
  14.     while(true)
  15.     {
  16.          c2=clock();
  17.          c=(c2-c1)/1000;      
  18.          cout<<(c2-c1)/1000<<"秒!";
  19.          system("cls");
  20.          if(c==sec)
  21.               break;  
  22.     }
  23.     cout<<"時間到! 共經過了"<<sec<<"秒!"<<endl;
  24.     system("pause");
  25.     system("cls");
  26.     goto re;     
  27.     return 0;   
  28. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. re:
  7. int sec;
  8. double c1,c2;
  9. int c;
  10. cout<<"請輸入你要數的秒數:";
  11. cin>>sec;
  12. c1=clock();
  13. while(true)
  14. {
  15. c2=clock();           
  16. c=(c2-c1)/1000;           
  17. cout<<(c2-c1)/1000<<"秒!";           
  18. system("cls");
  19. if(c==sec)
  20.   break;         
  21. }
  22. cout<<"時間到! 過了"<<sec<<"秒!"<<endl;     
  23.     system("pause");
  24.     system("cls");
  25.      goto re;
  26.     return 0;
  27. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     re:
  8.     int sec;
  9.     double c1, c2;
  10.     int c;
  11.     cout<<"輸入要數的秒數: ";
  12.     cin>>sec;
  13.     c1=clock();
  14.     while(true)
  15.     {
  16.          c2=clock();
  17.          c=(c2-c1)/1000;      
  18.          cout<<(c2-c1)/1000<<"秒!";
  19.          system("cls");
  20.          if(c==sec)
  21.               break;  
  22.     }
  23.     cout<<"time's up 共經過了"<<sec<<"秒!"<<endl;
  24.     system("pause");
  25.     system("cls");
  26.     goto re;     
  27.     return 0;   
  28. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     re:
  8.     system("cls");   
  9.     int sec;
  10.     int c;
  11.     double c1, c2;
  12.     cout << "請輸入要數的秒數:";
  13.     cin >> sec;
  14.     c1 = clock();
  15.     while (true)
  16.     {
  17.           c2 = clock();
  18.           c = (c2 - c1) / 1000;
  19.           cout << (c2 - c1) / 1000 << "秒" << endl;
  20.           system("cls");
  21.           if (c == sec)
  22.              break;
  23.     }
  24.     cout << "時間到!  經過了" << sec <<"秒" << endl;;
  25.     system("pause");
  26.     goto re;
  27.     return 0;   
  28. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;

  5. int main()
  6. {
  7.     re:
  8.     double c;
  9.     int sec;
  10.     cout << "請輸入要數的秒數:" ;
  11.     cin >> sec;
  12.     sec = sec*1000;
  13.     clock() == 0;
  14.     for(int i = 0;i<=sec;i++)
  15.     {
  16.     c = clock();
  17.     cout << c/1000 << endl;
  18.     system ("cls");  
  19.     if(clock() >= sec)
  20.     break;      
  21.     }
  22.     cout << "Time's up we run  "<<sec/1000 <<"seconds" << endl;
  23.     system("pause");
  24.     system("cls");
  25.     goto re;
  26.     return 0;
  27. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int sec;
  8.     double c1, c2;
  9.     int c;
  10.     cout<<"請輸入要數的秒數: ";
  11.     cin>>sec;
  12.     c1=clock();
  13.     while(true)
  14.     {
  15.        c2=clock();
  16.        c=(c2-c1)/1000;      
  17.        cout<<(c2-c1)/1000<<"秒!";
  18.        system("cls");
  19.        if(c==sec)
  20.            break;         
  21.     }
  22.     cout<<"時間到! 共經過了"<<sec<<"秒!"<<endl;
  23.     system("pause");     
  24.     return 0;   
  25. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     re:
  8.     int sec;
  9.     double c1,c2;
  10.     int c;
  11.     cout<<"請輸入要數的秒數: ";
  12.     cin>>sec;
  13.     c1=clock();
  14.     while(true)
  15.     {
  16.         c2=clock();
  17.         c=(c2-c1)/1000;
  18.         cout<<(c2-c1)/1000<<"秒!";
  19.         system("cls");
  20.         if(c==sec)
  21.             break;           
  22.     }
  23.     cout<<"時間到! 共經過了"<<sec<<"秒!"<<endl;
  24.     system("pause");
  25.     system("cls");
  26.     goto re;
  27.     return 0;
  28. }
複製代碼

TOP

返回列表