I need help with my ' if statement'

Below is a section of my coding, everything works fine except for the bolded section. Can someone please help explain why it won't output 'V' if the input isn't 'A' 'S' 'M' 'P' 'D'?
thank you



double num1, num2;

num1 = atof(argv[1]);
num2 = atof(argv[2]);

if ((argv[3][0]) == 'a')
{
cout<<num1 + num2<<endl;
TEST;
return 0;
}

if ((argv[3][0]) == 's')
{
cout<<num1 - num2<<endl;
TEST;
return 0;
}

if ((argv[3][0]) == 'm')
{
cout<<num1 * num2<<endl;
TEST;
return 0;
}

if ((argv[3][0]) == 'p')
{
cout<<pow(num1,num2)<<endl;
TEST;
return 0;
}

if (argv[3][0] == 'd')
{
cout<<num1 / num2<<endl;
TEST;
return 0;
}

if ((argv[3][0]) != 'a' || (argv[3][0]) != 's'|| (argv[3][0]) != 'p' || (argv[3][0]) != 'd' || (argv[3][0]) != 'm'))
{ cout <<"v"<<endl;
TEST;
return 0;
}



You are only checking for the lower case letters. In ASCII, uppercase letters have a different representation than lower case letters. Try checking for lower and uppercase values for each letter.

ex.
if (argv[3][0]!='a' && argv[3][0]!='A')...

Also, your using the inclusive or operator ("||"). That means that it can be anyone of those letters and still display. Try using the and operator ("&&").
I really appreciate your help, my program works now. Again, thank you very much !
Last edited on
Topic archived. No new replies allowed.