枚举\喜欢的颜色

#include
#include

enum COLOR {RED,YELLOW,GREEN,NumCOLORS};

int main(int argc,char const *argv[])
{
	//初始化
	int color = -1;
	char* COLORNAMES[NumCOLORS] = { "red","yellow","green" };
	char* colorName = NULL;	//空指针
	
	//输入代码
	for (int i = 0; i < NumCOLORS; i++)
	{
		printf("————%d.%s————\n",i+1,COLORNAMES[i]);
	}
	printf("请输入你喜欢的颜色代码:");
	scanf("%d",&color);
	color--;

	//判断
	if (color >= 0 && color < NumCOLORS)
		colorName = COLORNAMES[color];
	else
		colorName = "UNKNOWN";

	//输出
	printf("你喜欢的颜色是%s\n", colorName);

	system("pause");
	return 0;
}

你可能感兴趣的:(C语言进阶,c语言)