if else statement with char type didn't work

im doing a practical from my teacher, i have a problem here ,the if else statement didn't work for the char type

#include <iostream>
using namespace std;
int main(){
int ihour,imin,ohour,omin,hour,min;
char ctype;

cout<<"Please enter your vehicle type (Bus=b, Van=v, Car=c, Truck=t) ";
cout<<"\nVehicle type : ";
cin>>ctype;
if (ctype=='b'||'c'||'v'||'t'){} // it let any work bypass,'a' can go through here

else{
cout<<"Error, The vehicle type is only available for bus,car,van and truck(b,c,v,t)";
return 0;
}
Last edited on
That's because your if statement is wrong. This is how it should look like -

if (ctype == 'b' || ctype == 'c' || ctype == 'v' || ctype == 't')
First use code tags when posting code.

Next you can't combine logical operators as you have done. You need a complete comparison for each operator:

1
2
3
4
if(ctype == 'b' || ctype == 'c')
{
   // Your code here.
...
Thank you for helping, you are right i make a terrible mistake here
Topic archived. No new replies allowed.