本帖最後由 張絜晰 於 2023-8-3 20:53 編輯
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- int counter=0;
- re:
- counter++;
- int s[]={0,0,0,0};
- string h[]={"◆","★","▲","●"};
- srand(time(NULL));
-
- system("cls");
- cout<<"Racehorse thing: Round "<<counter<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0;i<=3;i++){
- cout<<h[i]<<endl;}
- system("pause");
- while(1)
- {
- system("cls");
- int r=rand()%4;
- s[r]++;
- cout<<"Race in progress..."<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0;i<=3;i++){
- for(int j=0; j<=s[i];j++){
- cout<<" ";
- }
- cout<<h[i]<<endl;
- }
- if(s[r]==73)
- break;
- _sleep(10);
- }
- system("cls");
- string win;
- for (int i=0;i<=3; i++){
- if (s[i]==73){
- win=h[i];}}
- cout<<"Race ended! The winner was:"<<win<<endl;
- cout<<"-------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0;i<=3;i++){
- for(int j=0; j<=s[i];j++){
- cout<<" ";
- }
- cout<<h[i]<<endl;
- }
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |