I am working through Ivor Horton's Beginning Visual C++ 2012, and I am doing exercise two in chapter three: Decisions and Loops. Here is my code:
#include <iostream>
using namespace std;
int main()
{
char letter;
int vowels = 0;
do
{
cout << "Enter a letter, and enter q or Q to end" << endl;
cin >> letter; // Enter a letter
switch (letter)
{
case 'a' || 'A' || 'e' || 'E' || 'i' || 'I' || 'o' || 'O' || 'u' || 'U': // If letter is a vowel, add to vowels variable
vowels++;
break;
default: // If letter is not a vowel, break loop
break;
}
} while (letter != 'Q' || letter != 'q');
cout << "You entered " << vowels << " vowels.";
return 0;
}
The intended purpose of this program is to allow the user to enter a letter until they enter q or Q, at which point the do...while loop ends and the program displays to the user the number of vowels they entered.
When I run this, the program does not quit when I enter Q or q. Why? How can I fix this?