Why this code shows wrong?

Can anyone tell me why this code is not passed in Problem Code : INTEST ?

#include<iostream>
using namespace std;

int main()
{
    int cases,numb,flag,temp;
    cin>>cases>>numb;

    for (int i = 0; i<cases; i++)
    {
        cin>>temp;
        if (temp%numb == 0)
        {flag++;}
    }
    cout<<flag;
    return 0;
}

Pay attention to compiler warnings! :slight_smile:

[simon@simon-laptop][18:00:43]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling iter8-INTEST.cpp
Executing command:
  g++ -std=c++17 iter8-INTEST.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG    -fsanitize=undefined -ftrapv
iter8-INTEST.cpp: In function ‘int main()’:
iter8-INTEST.cpp:15:11: warning: ‘flag’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   15 |     cout<<flag;
      |           ^~~~
Successful

please flag static

Initialise the flag to a particular value i.e 0

flag is a boolean type variable so define it like that or put particular value of flag .

Here the variable flag must be initialized.

@saanvi26 @hackthic2105 @deepastic @abhijeet2010

Look at the damn date bros, It’s literally 2023 and you’re answering it after a whole year