Contoh Penggunaan Switch Case di Program C
Contoh Coding Penggunaan Switch Case di Program C :
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main (){
int menu, makanan, minuman, bumbu, perabotan, kode_makanan, jumlah_makanan;
char namamakan[20], namaminum[20], namabumbu[20], namaperabotan[20];
do{
printf("\t\t\t --------------------------------------\n");
printf("\t\t\t Program Pengecekan Barang Toko Sembako\n");
printf("\t\t\t --------------------------------------\n");
printf("\n1. Makanan");
printf("\n2. Minuman");
printf("\n3. Bumbu Dapur");
printf("\n4. Perlengkapan Rumah Tangga");
printf("\n\nNomor Yang Ingin Anda Periksa : ");
scanf("%d,",&menu);
system("cls");
if (menu >4){printf("Input Salah\n");}
switch(menu){
case 1:
printf("\t\t-------\n");
printf("\t\tMakanan\n");
printf("\t\t-------\n\n");
printf("\n1.Tambah Data");
printf("\n2.Hapus Data");
printf("\nMasukan Pilihan Anda : ");
scanf("%d", &makanan);break;
case 2:
printf("\t\t-------\n");
printf("\t\tMinuman\n");
printf("\t\t-------\n\n");
printf("\n1.Tambah Data");
printf("\n2.Hapus Data");
printf("\nMasukan Pilihan Anda : ");
scanf("%d", &minuman);break;
case 3:
printf("\t\t-------\n");
printf("\t\tBumbu Dapur\n");
printf("\t\t-------\n\n");
printf("\n1.Tambah Data");
printf("\n2.Hapus Data");
printf("\nMasukan Pilihan Anda : ");
scanf("%d", &bumbu);break;
case 4:
printf("\t\t-------\n");
printf("\t\tPerabotan Rumah Tangga\n");
printf("\t\t-------\n\n");
printf("\n1.Tambah Data");
printf("\n2.Hapus Data");
printf("\nMasukan Pilihan Anda : ");
scanf("%d", &perabotan);break;
system("cls");
getch();
return 0 ;
}
}while(menu>4);
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main (){
int menu, makanan, minuman, bumbu, perabotan, kode_makanan, jumlah_makanan;
char namamakan[20], namaminum[20], namabumbu[20], namaperabotan[20];
do{
printf("\t\t\t --------------------------------------\n");
printf("\t\t\t Program Pengecekan Barang Toko Sembako\n");
printf("\t\t\t --------------------------------------\n");
printf("\n1. Makanan");
printf("\n2. Minuman");
printf("\n3. Bumbu Dapur");
printf("\n4. Perlengkapan Rumah Tangga");
printf("\n\nNomor Yang Ingin Anda Periksa : ");
scanf("%d,",&menu);
system("cls");
if (menu >4){printf("Input Salah\n");}
switch(menu){
case 1:
printf("\t\t-------\n");
printf("\t\tMakanan\n");
printf("\t\t-------\n\n");
printf("\n1.Tambah Data");
printf("\n2.Hapus Data");
printf("\nMasukan Pilihan Anda : ");
scanf("%d", &makanan);break;
case 2:
printf("\t\t-------\n");
printf("\t\tMinuman\n");
printf("\t\t-------\n\n");
printf("\n1.Tambah Data");
printf("\n2.Hapus Data");
printf("\nMasukan Pilihan Anda : ");
scanf("%d", &minuman);break;
case 3:
printf("\t\t-------\n");
printf("\t\tBumbu Dapur\n");
printf("\t\t-------\n\n");
printf("\n1.Tambah Data");
printf("\n2.Hapus Data");
printf("\nMasukan Pilihan Anda : ");
scanf("%d", &bumbu);break;
case 4:
printf("\t\t-------\n");
printf("\t\tPerabotan Rumah Tangga\n");
printf("\t\t-------\n\n");
printf("\n1.Tambah Data");
printf("\n2.Hapus Data");
printf("\nMasukan Pilihan Anda : ");
scanf("%d", &perabotan);break;
system("cls");
getch();
return 0 ;
}
}while(menu>4);
}
Post a Comment