คืออยากจะทราบมากเลยครับว่าต้องใช้คำสั่งอะไรอะครับเวลาที่เราใส่คำตอบผิด หรือใส่จำนวนเกิน หรือเลือกตัวเลือกที่ไม่ตรงกับที่กำหนดให้อะไรประมาณนี้อะครับ แล้วเราต้องการให้มันเริ่มโปรแกรมใหม่ตั้งแต่ต้นเลย ต้องใช้คำสั่งอะไรอะครับ (ผมพึ่งหัดเขียนนะครับ ;w;)
รูปแบบโค้ดครับ
#include<stdio.h>
#include<conio.h>
main()
{
char ch,name[15];
int type,total,piece;
printf("**********************Select menu*************************\n\n");
printf("Enter your name : ");
scanf("%s",&name);
printf("Please select your type : Enter number 1. General 200/piece\n");
printf(" Enter number 2. Member 100/piece\n");
printf("Select your type : ");
scanf("%d",&type);
printf("Enter piece : ");
scanf("%d",&piece);
switch(type)
{
do
{
case 1:total=piece*200;break;
case 2:total=piece*100;break;
default:printf("Enter 1 and 2 only.\n");
printf("Please any key to retry program.\n");
getch();
ch=getch();
}while(ch!=27);
}
printf("##########################################################\n");
printf("Your name : %s\n",name);
printf("Total(Piece) : %d\n",piece);
printf("Total(Bath) : %d\n\n",total);
printf("Please any key to end program.\n");
getch();
}
ลองทำตามในหนังสือแล้วก็งงๆ อยู่ เลยอยากจะรู้มากเลยครับว่าทำยังไง
[ภาษา C]ต้องการให้โปรแกรมเริ่มทำงานใหม่เมื่อใส่คำตอบผิดอะครับ
รูปแบบโค้ดครับ
#include<stdio.h>
#include<conio.h>
main()
{
char ch,name[15];
int type,total,piece;
printf("**********************Select menu*************************\n\n");
printf("Enter your name : ");
scanf("%s",&name);
printf("Please select your type : Enter number 1. General 200/piece\n");
printf(" Enter number 2. Member 100/piece\n");
printf("Select your type : ");
scanf("%d",&type);
printf("Enter piece : ");
scanf("%d",&piece);
switch(type)
{
do
{
case 1:total=piece*200;break;
case 2:total=piece*100;break;
default:printf("Enter 1 and 2 only.\n");
printf("Please any key to retry program.\n");
getch();
ch=getch();
}while(ch!=27);
}
printf("##########################################################\n");
printf("Your name : %s\n",name);
printf("Total(Piece) : %d\n",piece);
printf("Total(Bath) : %d\n\n",total);
printf("Please any key to end program.\n");
getch();
}
ลองทำตามในหนังสือแล้วก็งงๆ อยู่ เลยอยากจะรู้มากเลยครับว่าทำยังไง