if((choice == 'x') || (choice == 'X'))
{
// Square
}
if((choice == 'd') || (choice == 'D'))
{
// Divide
}
if((choice == 'a') || (choice == 'A'))
{
// Add
}
if((choice == 's') || (choice == 'S'))
{
// Subtract
}
This is bad style. The evaluation process continues even if the first one was true...also, instead of comparing both lower and uppercase, just convert the input into one or the other ( or else make a copy of it first to preserve the input)...
And Prodigy: I think you are confusing variables with the input expected...there is no need for more than one here.
Code:
#include < iostream.h>
int main ()
{
char c;
cout << "x=square d=divide a=add s=subtract q=square";
cin >> c;
c = tolower(c);
if( c == 'x' )
{
// Square
}
else
if( c == 'd' )
{
//...divide...
}
else
if( c == 'a' )
{
//...do addition...
}
else
if( c == 's' )
{
//...do subtraction...
}
else
if( c == 'q' )
{
//...do square...
}
return 0;
}
...also you could use a switch statement instead...