Example of Switch & Nested Switch: C Programming
Check in youtube
#include<stdio.h>
int main()
{
int phn_num, cs;
printf("Input your phone number: ");
scanf("%d", &phn_num);
start:
printf("\nSelect option\n1.Own Service.\n2.Package.\n3.Call a friend.\n>");
scanf("%d", &cs);
switch(cs)
{
case 1:
printf("1.Know your phone number.\n2.Goto main menu.\n>");
scanf("%d", &cs);
switch(cs)
{
case 1:
printf("Your phone number is: %d\n", phn_num);
goto start;
break;
case 2:
goto start;
break;
default:
printf("Error!\n");
goto start;
}
break;
case 2:
printf("1.100 SMS.\n2.Talktime\n3.Goto main menu.\n>");
scanf("%d", &cs);
switch(cs)
{
case 1:
printf("You brought 100 SMS\n");
goto start;
break;
case 2:
printf("You brought Talktime\n");
goto start;
break;
case 3:
goto start;
break;
default:
printf("Error!\n");
goto start;
}
break;
case 3:
printf("1.Call X.\n2. Call Y\n3.Goto main menu.\n>");
scanf("%d", &cs);
switch(cs)
{
case 1:
printf("You called X\n");
goto start;
break;
case 2:
printf("You called Y\n");
goto start;
break;
case 3:
goto start;
break;
default:
printf("Error!\n");
goto start;
}
break;
default:
printf("Error!\n");
goto start;
}
return 0;
}
Check in youtube
#include<stdio.h>
int main()
{
int phn_num, cs;
printf("Input your phone number: ");
scanf("%d", &phn_num);
start:
printf("\nSelect option\n1.Own Service.\n2.Package.\n3.Call a friend.\n>");
scanf("%d", &cs);
switch(cs)
{
case 1:
printf("1.Know your phone number.\n2.Goto main menu.\n>");
scanf("%d", &cs);
switch(cs)
{
case 1:
printf("Your phone number is: %d\n", phn_num);
goto start;
break;
case 2:
goto start;
break;
default:
printf("Error!\n");
goto start;
}
break;
case 2:
printf("1.100 SMS.\n2.Talktime\n3.Goto main menu.\n>");
scanf("%d", &cs);
switch(cs)
{
case 1:
printf("You brought 100 SMS\n");
goto start;
break;
case 2:
printf("You brought Talktime\n");
goto start;
break;
case 3:
goto start;
break;
default:
printf("Error!\n");
goto start;
}
break;
case 3:
printf("1.Call X.\n2. Call Y\n3.Goto main menu.\n>");
scanf("%d", &cs);
switch(cs)
{
case 1:
printf("You called X\n");
goto start;
break;
case 2:
printf("You called Y\n");
goto start;
break;
case 3:
goto start;
break;
default:
printf("Error!\n");
goto start;
}
break;
default:
printf("Error!\n");
goto start;
}
return 0;
}
No comments:
Post a Comment
পোস্ট সম্পর্কে মতামত দিন