I have been trying to solve a codechef competition question. In my program logic, everything works fine for the 1st and 2nd iteration and gives the desired result but during the second iteration the cin statement is completely getting ignored. However the next line having cout<<" ss ";
works just fine.
I have already searched for possible workarounds on stack overflow, they said to use cin.clear() and cin.ignore() and I used it but still no effect. Am i doing something wrong?
Here is the link to the problem https://www.codechef.com/problems/DIET
#define REP(limit) for(int i = 0; i < limit; i++)
#define REP2(limit2) for(int j = 0; i < limit2; j++)
int main()
{
int testcases;
cin>>testcases;
while(testcases--){
int days, diet, current = 0;
cin>>days>>diet;
bool res = true;
REP(days){
int x;
cin>>x;
cout<<" ss ";
current += x;
if(current < diet){
cout<<"NO "<<i+1;
res = false;
break;
}
current -= diet;
}
if(res == true){
cout<<"YES";
}
}
return 0;
}