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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started