2016-09-21 4 views
-1

私はコンウェイの人生のゲームを書いています。コードは完全に実行されますが、コンソールウィンドウで実行した後、「クリア」コマンドのスペルが間違っているか、 が見つかりませんでした。私はその点を得ていない。なぜこれが起こっているのですか?どうすればclearコマンドを修正できますか?コンウェイの生活ゲームのエラー

#include <iostream> 
#include <string> 
#include <stdio.h> 
#include <stdlib.h> 
#include <time.h> 

using namespace std; 

void copy(int array1[10][10], int array2[10][10]) 
{ 
    for(int j = 0; j < 10; j++) 
    { 
     for(int i = 0; i < 10; i++) 
      array2[j][i] = array1[j][i]; 
    } 
} 


void life(int array[10][10], char choice) 
{ 

    int temp[10][10]; 
    copy(array, temp); 
    for(int j = 0; j < 10; j++) 
    { 
     for(int i = 0; i < 10; i++) 
     { 
      if(choice == 'm') 
      { 

       int count = 0; 
       count = array[j-1][i] + 
        array[j-1][i-1] + 
        array[j][i-1] + 
        array[j+1][i-1] + 
        array[j+1][i] + 
        array[j+1][i+1] + 
        array[j][i+1] + 
        array[j-1][i+1]; 

     if(count < 2 || count > 3) 
        temp[j][i] = 0; 

     if(count == 2) 
        temp[j][i] = array[j][i]; 

     if(count == 3) 
        temp[j][i] = 1; 
      } 


     } 
    } 

    copy(temp, array); 
} 


bool compare(int array1[10][10], int array2[10][10]) 
{ 
    int count = 0; 
    for(int j = 0; j < 10; j++) 
    { 
     for(int i = 0; i < 10; i++) 
     { 
      if(array1[j][i]==array2[j][i]) 
       count++; 
     } 
    } 

    if(count == 10*10) 
     return true; 
    else 
     return false; 
} 


void print(int array[10][10]) 
{ 
    for(int j = 0; j < 10; j++) 
    { 
     for(int i = 0; i < 10; i++) 
     { 
      if(array[j][i] == 1) 
       cout << '*'; 
      else 
       cout << ' '; 
     } 
     cout << endl; 
    } 
} 

int main() 
{ 
    int gen0[10][10]; 
    int todo[10][10]; 
    int backup[10][10]; 
    char neighborhood; 
    char again; 
    char cont; 
    bool comparison; 
    string decoration; 




    do 
    { 

    do 
     { 
     cout << "Which neighborhood would you like to use (m): "; 
      cin >> neighborhood; 
     }while(neighborhood != 'm'); 

    system("clear"); 
    int i = 0; 

    do 
     { 

      srand(time(NULL)); 

      for(int j = 0; j < 10; j++) 
      { 
       for (int i = 0; i < 10; i++) 
        gen0[j][i] = rand() % 2; 
      } 



     if(i == 0) 
       copy(gen0, todo); 
      copy(todo, backup); 
      print(todo); 
      life(todo, neighborhood); 
      i++; 


     system("sleep .5"); 

     if(i % 10 == 1 && i != 1) 
     { 
     cout << endl; 

     do 
     { 
      cout << "Would you like to continue this simulation? (y/n): "; 
      cin >> cont; 
     }while(cont != 'y' && cont != 'n'); 
     if(cont == 'n') 
      break; 
     } 

     comparison = compare(todo, backup); 
     if(comparison == false) 
     system("clear"); 
     if(comparison == true) 
     cout << endl; 
     }while(comparison == false); 

    do 
    { 
     cout << "Would you like to run another simulation? (y/n): "; 
      cin >> again; 
    }while(again != 'y' && again != 'n'); 
    }while(again == 'y'); 
    return 0; 
} 
+0

:またあなたが見に興味がある可能性がありsystem("CLS")

で試してみてください。あなたのオペレーティングシステムとは何ですか?どのシェルを使用していますか? – Hayt

答えて

0

ウィンドウクリア方法はシステムによって異なります。 Yoursはコマンド「クリア」を知らないように見えます。私は、これはあなたがそれを実行しようとするOS /コンソールに依存推測system("clear"); not working but system("cls"); works

+0

ありがとう –

関連する問題