// Program Switches demonstrates the use of the Switch
// statement.
#include <iostream>
usingnamespace std;
int main ()
{
char letter;
int first;
int second;
int answer;
cout << "Enter an A for addition or an S for"
<< " subtraction, followed by two integer numbers."
cout << "Enter an A for addition or an S for"
<< " subtraction, followed by two integer numbers."
<< endl << "Press return. Enter a Q to quit." << endl;
cin >> letter;
while (letter != 'Q')
{
cin >> letter;
while (letter != 'Q')
{
cin >> first >> second;
switch (letter)
{
case'A': answer = (first + second);
cout << first << " + " << second
<< " is " << answer << endl;
break;
case'B': answer = (first - second);
cout << first << " - " << second
<< " is " << answer << endl;
break;
}
cin >> letter;
}
return 0;
}
my questions are
1- add the code necessary to allow the program to work properly with both Lowercase and uppercase versions of the input letters?
2- add a default case that prints an error message and asks for the letter to be reentered?
switches.cpp: In function `int main ()':
switches.cpp:25: `var' undeclared (first use this function)
switches.cpp:25: (Each undeclared identifier is reported only once for
each function it appears in.)
switches.cpp:36: parse error before `;'
switches.cpp:28: duplicate case value `'a''
switches.cpp:27: previously used here
switches.cpp:32: duplicate case value `'B''
switches.cpp:27: previously used here
switches.cpp:33: duplicate case value `'b''
switches.cpp:27: previously used here