0

I'm fairly new to c++ and programming in general. I want to be able to test for the origLetter char. However, it could be 'a' or 'A'. When I attempt to execute my program it throws back an error. "Error: duplicate case values". I want to include both of the case values. How do I get around this?

using namespace std;

int main() {
   char origLetter;

   cin >> origLetter;

   switch (origLetter) {
   case 'A'||'a':
      cout << "Alpha" << endl;
      break;
   case 'b'||'B':
      cout << "Beta" << endl;
      break;
   default:
      cout << "Unknown" << endl;
      break;
   }
  • 1) `case 'A'||'a':` -> `case 'A': case 'a':` The same for other `case`s. 2) "_I'm fairly new to c++ and programming in general._" You won't go far in C++, by coding randomly. Consider learning from a [good C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Algirdas Preidžius Nov 11 '20 at 03:18

1 Answers1

3

The correct syntax is:

switch (origLetter) {
   case 'A':
   case 'a':
      cout << "Alpha" << endl;
      break;
   case 'b':
   case 'B':
      cout << "Beta" << endl;
      break;
   default:
      cout << "Unknown" << endl;
      break;
   }