Please help me in identifying my error INSIDE THE STADIUM problm

I am supposed to get the output as 2 0 3 for the sample test cases, but i am getting 3 1 3 . I have used the correct formula to calculate the strike rate but stil i am not getting correct. Don’t want other solution, just want to know went wrong with this code.

include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
int t; cin>>t;
while(t–){
int cnt=0, r=0;//r–>runs,
int n;
cin>>n;
//input array.
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}

for(int i=0;i<n;i++){
    r+=a[i];
    int sr=(float(r/(i+1)))*100;
    if(sr==100) cnt++;
}
cout<<cnt<<endl;

}
}

Here r/(i+1) gives an integer . So even if value is 1.3 it gives as 1. And float outside in your code just makes it 1.00. And int sr stores 100 which is wrong actually and result is increasing.

Follow below code


for(int i=0;i<n;i++){
    r+=a[i];
    float sr=(float(r/float(i+1)))*100;
    if(sr==100) cnt++;
}