Question: Hey I need help with a code for the assignment on this page: http://bytes.usc.edu/cs103/coursework/zombies/ When I input their test cases my code is slightly off

Hey I need help with a code for the assignment on this page: http://bytes.usc.edu/cs103/coursework/zombies/

When I input their test cases my code is slightly off and I cannot figure out why

Here is my code so far:

#include

#include

#include

#include

using namespace std;

const int MAXPOP = 100000;

int main()

{

bool pop[MAXPOP];

int N,k, M, s;

int min = 100;

int max = 0;

double nightssum = 0;

int kog; // cuz k changes

int nights = 0; //counter that tells number of nights passed in that simu

cout << "Enter Values separated by white space" << endl;

cin >> N >> k >> M >> s;

srand(s);

kog = k;

for(int i = 0; i < M;i++){

k = kog;

for(int i = 0;i

pop[i]=true;

}

for(int i = k;i

pop[i]=false;

}

nights = 0;

while(pop[N-1] == false){ //While there are humans keep running

int zombegatnight = k; //zombies at beginning of night

for(int i = 0;i

if(pop[rand() % N] == false){

pop[k] = true; // so that the first k are always zombies

k++;

}

}

nights++; //keeps track of nights

}

nightssum += nights;

if(max < nights){

max = nights;

}

if(min > nights){

min = nights;

}

nights = 0;

}

cout << "Average Nights:" << " " << (nightssum/M) << endl;

cout << "Max Nights:" << " " << max << endl;

cout << "Min Nights:" << " " << min << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!