I am doing some Programming exercises from the book I am learning C++ from, C++ Primer Plus. I was doing one of the examples and I have ran into a problem with some of my code.
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Please enter one of the following choices: \n";
cout << "c) carnivore p)pianist\nt)tree g)game\n";
char in;
cin >> in;
while( in != 'c' || 'p' || 't' || 'g'){
cout<<"Please enter a c, p, t, or g: ";
cin >> in;
}
cout<< endl;
switch(in){
case 'c':
cout<<"A lion is a carnivore.";
break;
case 'p':
cout<<"A pianist is a piano player";
break;
case 't':
cout<<"A maple is a tree.";
break;
case 'g':
cout<<"Mine sweeper is a game.";
break;
}
return 0;
}
I believe everything is working as I want except for the while loop
Code:
while( in != 'c' || 'p' || 't' || 'g'){
cout<<"Please enter a c, p, t, or g: ";
cin >> in;
}
I have tried putting the stuff on the right side of the != in parenthesis, changing it to a == and putting a ! infront of the entire thing.
Does anyone have any suggestions on what might be wrong with my code? I am not able to see what all is wrong.