Can somebody explain this code to me.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(){
srand(time(0));
int year = 365;
int people = 0;
int daycnt = 0;

bool found[year] = {false};

while(daycnt<year){
people++;
int birthday = (int)(rand() % year+1);
cout<<birthday<<endl;
if (found[birthday] == true){
daycnt++;
cout<<"When the "<<people<<"th person entered the room, a pair had matching birthdays."<<endl;
break;}
found[birthday] = true;
}
}

closed account (E0p9LyTq)
What do you think this program does? Did you run it to see what it does?
Well you already added one debug cout statement, so add another

cout << "The number of people in the room is " << people << endl;

Topic archived. No new replies allowed.