predator and prey

This is a discussion on predator and prey within the C++ Programming forums, part of the General Programming Boards category; heeey guys i want to make predator and prey simulation and i made the 2d array i just don't know ...

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    1

    predator and prey

    heeey guys
    i want to make predator and prey simulation and i made the 2d array i just don't know what to do next
    i need help !!!!

    Code:
     #include <iostream>
    using namespace std;
    void printGrid(char grid[][20], int w, int h);
    
    
    int main() {
    
        // Create a 20 by 20 grid array of chars
    
        char grid[20][20];
    
        // Now loop through each row...
    
        for (int i = 0; i < 20; i++) {
    
            // ... then each column and set each space to '.'
    
            for (int j = 0; j < 20; j++) {
    
                grid[i][j] = '.';
    
            }
    
        }
    
     
    
        // Print the grid of 20 by 20 dots
    
        printGrid(grid,20,20);
    
     
    
        return 0;
    	std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
       std::cin.get();
    }
    
     
    
     
    
    // Call this function to print your grid. w = width, h = height
    
    void printGrid(char grid[][20], int w, int h) {
    
        for (int i = 0; i < w; i++) {
    
            for (int j = 0; j < h; j++) {
    
                cout << grid[i][j] << " ";
    
            }
    
            cout << endl;
    
        }
    
    }

  2. #2
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    455
    predator and prey as in Lotka-Volterra differential equation? then you need to read on how to solve numerical ODE like the Runge-Kutta method.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,053
    So before you run in and write another function, write main. Write in main what the program is going to do. Is there a loop? What happens each iteration?
    Don't worry about how to do each step, just stub out the functions so that you can fill them in later.

    On a similar note initializing the array to all '.' should be done in it's own function.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,687
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Predator Prey help please
    By wannabec++ in forum Game Programming
    Replies: 0
    Last Post: 12-05-2010, 01:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21