getting error when i run this practise code which is naive chef found in beginner section

i am getting 0 percent result when i run the following code.
this is a very simple question but i the length of the code in increased because of the constraints given over there. Naive Chef

#include <iostream>
#include<iomanip>

using namespace std;

int main()
{
    int cases,faces,num1,num2,num_count1,num_count2,i;
    double prob;
    cin>>cases;
    if(cases<=70 && cases>=1)
    {
        for(int j=0;j<cases;j++)
        {
            cin>>faces>>num1>>num2;
            int * num,flag=0;
            num=new int[faces];
            if(faces<=10000 && faces>=1 && num1>=1 && num1<=faces && num1>=1 && num1<=faces)
            {

                    for(i=0;i<faces;i++)
                    {
                        cin>>num[i];
                    }
                    for(i=0;i<faces;i++)
                    {
                        if(!(num[i]<=faces && num[i]>=1))
                           {
                               flag=1;
                               break;
                           }
                    }
                    if(flag==0)
                    {
                        num_count1=num_count2=0;
                        for(i=0;i<faces;i++)
                        {
                            if(num1==num[i])
                            {
                                num_count1++;
                            }
                            else if(num2==num[i])
                            {
                                num_count2++;
                            }
                        }

                        prob=(double)num_count1/faces;
                        prob*=(double)num_count1/faces;
                        cout<<setprecision(7)<<prob<<endl;
                    }
            }
            delete []num;
        }
    }
}

i am running this in my compiler it is working fine. pl help. bear with me as i am completely new (started learning cpp a weak ago).

I saw your code. There are 2 errors in your code first when you are checking how many occurences of num1 and num2 are there you are using else if you see a can be equal to b so you should use only if there. second in this
prob*=(double)num_count1/faces;
you are again multiplying with num_count1/faces you should multiply with num_count2/faces
so it should be
prob*=(double)num_count2/faces;
I corrected These and got 100% results see https://www.codechef.com/viewsolution/18874764

As @ssp547 corrected the solution, I want to highlight a different aspect in your code. You have checked at every stage that the input was correct or not. This is not needed at all in competitive programming. The input is guaranteed to be according to the constraints. So no need to check it and save time. This will help you in short contests.

ok thanks. I am just new to programming. didn’t thoroughly rechecked it. thanks for support

ok as i said i am new to programming. thanks for support

1 Like