Can anyone help me with this one? I have the following code and produces an output, but the Probability stays at 1 regardless of how many students I input....Any ideas?

#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;


void main()
{
	int numStudents, DayOfBirth, cnt;
	double Probability, Power;

	cout << "Enter Number of Students in The Room: " << endl;
	cin >> numStudents;
	cout << endl;


	Power = (numStudents * (numStudents - 1)) / 2;
	Probability = (1 - pow((364)/(365) , Power));

	cnt = 0;
	while (cnt < numStudents)
	{
		DayOfBirth = rand() % 365;
		cout << "Student Date of Birth is: " << DayOfBirth << endl;
		cnt++;
	}
	cout << "Number of Students is: " << cnt << endl;
	cout << "Probability of sharing DOB: " << Probability << endl;

}

Edited 6 Years Ago by PDB1982: n/a

For your ratio try 364.0/365.0, you probably keep getting 0 for 364/365 since it's still considered integer division.

For your ratio try 364.0/365.0, you probably keep getting 0 for 364/365 since it's still considered integer division.

Yep, that did it! Thanks!

This question has already been answered. Start a new discussion instead.