Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

How were the HR functions affected by Hurricane Rita?

Answered: 1 week ago

Question

What information might lead you to choose working for the company?

Answered: 1 week ago

Question

Which environment factor(s) did Hurricane Rita affect? Discuss.

Answered: 1 week ago