WA in HOLES

The following code gave WA.


#include <iostream>
using namespace std;
 
int holesCalc(char c)
{
	int hole;
	if(c=='A' | c=='Q' | c=='D' | c=='O' | c=='P' | c=='R')
	 	hole=1;
	else if(c=='B')
		hole=2;
	else
		hole=0;
	return hole;
}
 
int main()
{
	char a[100]; int holes;
	int t;
	cin>>t;
	while(t>0){
	holes=0;
	cin>>a;
	for(int i=0;a[i]!='\0';i++)// your code goes here
	holes=holes + holesCalc(a[i]);
	cout<<holes;
	t--;
	}
	return 0;
} 


You are using Arithmetic OR instead of logical OR in the holesCalc(char) function.

2 Likes

Still, it says WA.

Add a ā€˜\nā€™ after printing the answer.

1 Like

You forgot newline and use || instead of |.

cout << holes << endl;

This should work.

1 Like

Thanks! It worked :smiley:

Thanks! It worked :smiley:

1 Like