C 枚舉

枚舉是一個數據類型,可以先定義一個枚舉類型後定義變量,或者同時進行


//簡單示例代碼
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
	enum weekend{monday = 1,tuesday,wednesday,thursday,friday,saturday,sunday};
	enum weekend day;
	int k;
	int i = 0;
	for(i = 0; i < 7;i++)
	{
		printf("\tinput the day you have workded!\n");
		scanf("%d",&k);
		day = (enum weekend)k;
		switch(day)
		{
		case monday:
			printf("fuck!today is monday");
			break;
		case tuesday:
			printf("so good!today is tuesday");
			break;
		case wednesday:
			printf("come on!today is wednesday");
			break;
		case thursday:
			printf("aha!in the middle1 of the week!today is thursday");
			break;
		case friday:
			printf("today is sunday,tomorrow you will have a rest,hah!");
			break;
		default:
			printf("go for a weekend!may you have a good time!");
		}

	}
	return EXIT_SUCCESS;
}


練習玩玩

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章