2016-09-21 3 views
-1

Ich schreibe Conways Spiel des Lebens. Der Code läuft perfekt, aber nach dem Ausführen im Konsolenfenster wird geschrieben, dass "der Befehl" clear "entweder falsch geschrieben wurde oder nicht gefunden wurde." Ich verstehe den Punkt nicht. Warum passiert das? Wie kann ich den Befehl löschen?Conways Spiel des Lebens Fehler

#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

Ich denke, das hängt von dem O/console Sie versuchen, um es auszuführen. Was ist Ihr Betriebssystem und welche Shell verwenden Sie? – Hayt

Antwort

Verwandte Themen