The following program compiles, but if I enter a, s, m, or d, it says they're invalid. I want to use the toupper function so that the program will accept lowercase a, s, m, and d as well as uppercase A, S, M, and D. But I don't know where to put it. Please help me!
CODE
#include <iostream>
using namespace std;
int main ()
{
//declare variables
char operation = ' ';
int num1 = 0;
int num2 = 0;
int result = 0;
//calculate and display
cout << "Enter operation (A/S/M/D): ";
cin >> operation;
if (operation != 'A', 'a' && operation != 'M', 'm' && operation != 'D', 'd' && operation != 'S', 's')
{
cout << "Invalid operator" << endl;
return 0;
}
else
cout << "Enter first number: ";
cin >> num1;
cout << "Enter second number: ";
cin >> num2;
switch (operation)
{
case 'A':
result = num1 + num2;
cout << "Result: " << result << endl;
break;
case 'M':
result = num1 * num2;
cout << "Result: " << result << endl;
break;
case 'S':
if (num2 > num1)
{
int temp = 0;
temp = num2;
num2 = num1;
num1 = temp;
result = num1 - num2;
cout << "Result: " << result << endl;
}
else
{
result = num1 - num2;
cout << "Result: " << result << endl;
} //end if
break;
case 'D':
if (num2 > num1)
{
int temp = 0;
temp = num2;
num2 = num1;
num1 = temp;
result = num1 / num2;
cout << "Result: " << result << endl;
}
else
{
result = num1 / num2;
cout << "Result: " << result << endl;
} //end if
break;
} //end switch
//end if
return 0;
}
This post has been edited by ladylindsay: 30 Sep, 2008 - 07:44 PM