Can somebody explain this code to me.

Feb 28, 2019 at 7:28am
#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;
}
}

Feb 28, 2019 at 8:14am
closed account (E0p9LyTq)
What do you think this program does? Did you run it to see what it does?
Feb 28, 2019 at 10:08am
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.