本帖最後由 葉桔良 於 2022-8-6 17:34 編輯
設計一動畫由
0% 載入中 □□□□□□□□□□
慢慢改變為
27% 載入中 ■■□□□□□□□□
最後
100% 完成!
備註:後方的黑色方塊在進度達 10% 為一個、達 20% 為兩個 ... 依此類推。
執行畫面如下:



補充: 需有控制速度的機制 (清楚地知道修改那個程式碼可以改變速度)
載入中 - 方塊.exe- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- for(int i=0; i<100; i++)
- {
- if(i<10)
- cout<<" "<<i<<"% 載入中 ";
- else
- cout<<" "<<i<<"% 載入中 ";
- if(i<10)
- cout<<"□□□□□□□□□□"<<endl;
- else if(i<20)
- cout<<"■□□□□□□□□□"<<endl;
- else if(i<30)
- cout<<"■■□□□□□□□□"<<endl;
- else if(i<40)
- cout<<"■■■□□□□□□□"<<endl;
- else if(i<50)
- cout<<"■■■■□□□□□□"<<endl;
- else if(i<60)
- cout<<"■■■■■□□□□□"<<endl;
- else if(i<70)
- cout<<"■■■■■■□□□□"<<endl;
- else if(i<80)
- cout<<"■■■■■■■□□□"<<endl;
- else if(i<90)
- cout<<"■■■■■■■■□□"<<endl;
- else if(i<100)
- cout<<"■■■■■■■■■□"<<endl;
- _sleep(100); //休眠100毫秒
- system("cls");
- }
- cout<<"100% 完成! ■■■■■■■■■■"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |