My issue
Can someone expalin where did my code logic fail
include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin>>T;
while(T–)
{
int D;
cin>>D;
int d;
cin>>d;
int P;
cin>>P;
int Q;
cin>>Q;
int sum=0;
int x=1;
int y=P;
for(int i=1;i<=D;i++)
{
if(i==(xd+1))// As after every ‘d’ days the money get updated to P+qd this statment will find the next day from where the money will updated and make the change in rate.
{
y= P+ xQ;
x++;
//sub=x*d;
}
sum=sum+y;
}
cout<<sum<<endl;
}
}
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin>>T;
while(T--)
{
int D;
cin>>D;
int d;
cin>>d;
int P;
cin>>P;
int Q;
cin>>Q;
int sum=0;
int x=1;
int y=P;
for(int i=1;i<=D;i++)
{
if(i==(x*d+1))
{
y= P+ x*Q;
x++;
//sub=x*d;
}
sum=sum+y;
}
cout<<sum<<endl;
}
}
Problem Link: Bella ciao Practice Coding Problem