คือตอนนี้ต้องเขียนโปรแกรมส่งอาจารย์อยู่โดยมีโจทย์ว่า ทำอะไรก็ได้ ผมเลยทำเกี่ยวกับการสั่งอาหารแล้วทีนี้ผมจะให้มีตัวเลือกระหว่าง เป็นชิ้น กับเป็นชุดโดยใช้ switch case แต่ผผผผมลองทำแล้วมันไม่ได้ เลยอยากให้บอกวิธีหรือช่วยบอกจุดที่ต้องเอาไปใส่หน่อยครับ
int p,i,m,burgerpork = 35,burgerchicken = 35,frenchfries = 20,icecream = 10,pepsi= 15,water = 10;
int choice;
float n;
printf("\t-Cake My Lover-\n");
printf("Select Menu:\t1.Burger Pork = 35\n \t\t2.Burger Chicken = 35\n \t\t3.French Fries = 20\n \t\t4.Ice Cream = 10\n \t\t5.Pepsi= 15\n \t\t6.Water = 10\n");
printf("Select:");
scanf("%d",&choice);
switch(choice){
case 1:printf("\n\n1. Burger Pork = 35 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*burgerpork;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
case 2:printf("\n\n2. Burge Chicken = 35 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*burgerchicken;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
case 3:printf("\n\n3. French Fries = 20 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*frenchfries;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
case 4:printf("\n\n4. Ice Cream = 10 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*icecream;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
case 5:printf("\n\n5. Pepsi = 15 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*pepsi;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
case 6:printf("\n\n6. Water = 10 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*water;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
}
switch ซ้อน switch(ภาษา C)
int p,i,m,burgerpork = 35,burgerchicken = 35,frenchfries = 20,icecream = 10,pepsi= 15,water = 10;
int choice;
float n;
printf("\t-Cake My Lover-\n");
printf("Select Menu:\t1.Burger Pork = 35\n \t\t2.Burger Chicken = 35\n \t\t3.French Fries = 20\n \t\t4.Ice Cream = 10\n \t\t5.Pepsi= 15\n \t\t6.Water = 10\n");
printf("Select:");
scanf("%d",&choice);
switch(choice){
case 1:printf("\n\n1. Burger Pork = 35 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*burgerpork;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
case 2:printf("\n\n2. Burge Chicken = 35 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*burgerchicken;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
case 3:printf("\n\n3. French Fries = 20 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*frenchfries;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
case 4:printf("\n\n4. Ice Cream = 10 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*icecream;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
case 5:printf("\n\n5. Pepsi = 15 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*pepsi;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
case 6:printf("\n\n6. Water = 10 bath: ");
printf("\n\nEnter number of products: ");
scanf("%d",&p);
printf("Enter amount of money: ");
scanf("%f",&n);
i = p*water;
printf("\n\nThe total number of items = %d",p);
printf("\n\nThe total amount of money = %d",i);
m=n-i;
printf("\n\nChange = %d Bath \n\n",m);break;
}