String array HELP

closed account (ivDwAqkS)
Is there any way to fix this bug? I would like to print the string array but if some of the element is not a or c, it has to change the letter to X. why it doesn't print?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;
string arr[5]={"a", "b", "c", "d", "e"};

int main(){
  int counter;
  for(counter = 0; counter < 5; counter++){
     if(arr[counter]!= "c" || arr[counter]!= "a")//this doesn't print why?
       cout << "X" << endl;                    //correction: change || for &&
     else
       cout << arr[counter] << endl;
  }
  return 0;
}
Last edited on
You used the logical-or operator instead of the logical-and operator. It can't be both a and c at the same time, so one of the conditions always fails.
closed account (ivDwAqkS)
so I just have to change it by &&? THANKS L B
Last edited on
Topic archived. No new replies allowed.