我试图做一个 switch 语句,要求用户输入一封信。取决于输入。用户将获得电子色码图的色码编号。如果颜色不在电子色码表中,则输出“未知颜色”。当用户输入“b”时我遇到了问题。如何让 switch 语句只输出棕色、蓝色或黑色。我不能使用任何 if、else 语句。*/
#include <stdlib.h> // Directive for Pause
#include <iostream> // Directive for Input / Output
using namespace std;
int main ()
{
char first_letter;
char second_letter;
char third_letter ;
char electronic_color_code;
cout << "Electronic Color Code" << endl << endl;
cout << "To find out the digit of a particular color code," << endl <<
"enter a letter: " ;
cin >> electronic_color_code;
cout << endl;
switch (electronic_color_code)
{
case 'r':
case 'R':
cout << "Red stands for digit 2.";
break;
case 'o':
case 'O':
cout << "Orange stands for digit 3.";
break;
case 'y':
case 'Y':
cout << "Yellow stands for digit 4.";
break;
case 'v':
case 'V':
cout << "Violet stands for digit 7.";
break;
case 'w':
case 'W':
cout << "White stands for digit 9.";
break;
case 'b':
case 'B':
cout << "Enter a second letter: ";
cin >> second_letter;
cout << endl;
case 'brows':
case 'BROWS':
cout << "Brown stands for digit 1.";
cout << endl;
break;
case 'lue':
case 'LUE':
cout << "Enter a third letter: ";
cin >> third_letter;
cout << endl;
case 'a':
case 'A':
cout << "Black stands for digit 0.";
cout << endl;
case 'u':
case 'U':
cout << "Blue stands for digit 6.";
break;
case 'g':
case 'G':
cout << "Enter the second and third letter" << endl;
cin >> second_letter >> third_letter ;
case 'rayd':
case 'RAYD':
cout << "Grey stands for the digit 8.";
case 0:
case 'reen':
case 'REEN':
cout << "Green stands for the digit 5." ;
break;
default:
cout << "Unknown Color";
}
cout << endl << endl;
system ("Pause");
return 0;
}