How do I print only Yes or No once, it is printing both yes and no for one input. I am not able to break the statement

#include
using namespace std;
int main() {
int n,carNum,lastDigit,sumEven=0,sumOdd=0;
cin>>n;
for(int i=0;i<n;i++){
cin >> carNum;
while(carNum!=0){
lastDigit=carNum%10;
if(lastDigit%2==0){
sumEven=sumEven+lastDigit;
}
else if(lastDigit%2!=0){
sumOdd+=lastDigit;
}
carNum=carNum/10;

}
if(sumEven%4==0){
cout<<“Yes”<<endl;
}
else if(sumEven%4!=0){
cout<<“No”<<endl;
}
else if(sumOdd%3==0){
cout<<“Yes”<<endl;
}
else if(sumOdd%3!=0){
cout<<“No”<<endl;
}

}
return 0;
}

mention problem link and paste your code on coding blocks IDE and share the link here.

Use a Flag variable, Whenever you have printed yes or no set the flag to true and it will not enter any other if else. Enter if else if flag is false.

and please mention problem link if doubt is different.

Hit like if you get it
Cheers :stuck_out_tongue:
Happy coding :smiley:

Hey Anikash, both yes and no are printing because there is no need to use 4 if - else if conditions in your code, you can solve it just by 2. Update your if and else if conditions like this

if(sumEven%4==0 || sumOdd%3==0){
cout<<“Yes”<<endl;
}
else if(sumEven%4!=0 && sumOdd%3!=0){
cout<<“No”<<endl;
}