Code menu lựa chọn trong C

Code: C 19/02/2021 07:42

#include <stdio.h>
void main(){
	int chon ;
	do{
		system("cls"); // lenh xoa man hinh
		printf("----------MENU----------\n");
		printf("1. Chuong trinh 1\n");
		printf("2. Chuong trinh 2\n");
		printf("3. Chuong trinh 3\n");
		printf("0. Thoat \n");
		printf("Moi ban chon menu: ");
		scanf("%d", &chon);
		
		switch(chon){
			case 1: 
				printf("Thuc hien cong viec 1, goi ham 1");
			break;
			case 2: 
				printf("Thuc hien cong viec 2, goi ham 2");
			break;
			case 3: 
				printf("Thuc hien cong viec 3, goi ham 3");
			break;
			default:
				printf("Ket thuc chuong trinh");
			break;
		}
		
		printf("Ban co muon tiep tuc khong? (Nhap y/n)");
		char c ;
		fflush(stdin);
		scanf("%c", &c);
		if(c == 'y'){
			chon = -1; // gan chon khong phai la 1,2,3,0 thi chuong trinh se lap lai
		}else{
			printf("Tam biet!");
		}
		  
	}while(chon != 1 && chon != 2 && chon !=3 && chon!=0);
	
	

}