The above program is an extended version of the previous program which demonstrates the use of the goto statement along with a switch statement.
As I previously mentioned, the use of goto statement is considered as a bad practice in programming and it makes the program harder to read and understand, and can lead to hard to debug spaghetti code. Instead of using goto statement, programmers should use structured control flow statements like while, do-while, for loop etc.
#include<stdio.h> int main() { int ch,qty,i,net=0; joes: printf("\n\tMENU CARD"); printf("\n\t\t1.COFFEE Rs:15"); printf("\n\t\t2.TEA Rs:10"); printf("\n\t\t3.COLD COFFEE Rs:25"); printf("\n\t\t4.MILK SHAKE Rs:50"); printf("\n\n Enter Your choice : "); scanf("%d",&ch); switch(ch) { case 1: printf("\nYou have selected Coffee"); printf("\nEnter The Qty : "); scanf("%d",&qty); net=net+(qty*15); break; case 2: printf("\nYou have selected Tea"); printf("\nEnter The Qty : "); scanf("%d",&qty); net=net+(qty*10); break; case 3: printf("\nYou have selected Cold Coffee"); printf("\nEnter The Qty : "); scanf("%d",&qty); net=net+(qty*25); break; case 4: printf("\nYou have selected Milk Shake"); printf("\nEnter The Qty : "); scanf("%d",&qty); net=net+(qty*50); break; default: printf("\nInvalid Product Selection"); break; } printf("\nDo You want to continue press 1: "); scanf("%d",&i); if(i==1) { goto joes; } printf("\nTotal amount : %d",net); printf("\nThank You Come Again"); return 0; }To download raw file Click Here
MENU CARD 1.COFFEE Rs:15 2.TEA Rs:10 3.COLD COFFEE Rs:25 4.MILK SHAKE Rs:50 Enter Your choice : 1 You have selected Coffee Enter The Qty : 3 Do You want to continue press 1: 1 MENU CARD 1.COFFEE Rs:15 2.TEA Rs:10 3.COLD COFFEE Rs:25 4.MILK SHAKE Rs:50 Enter Your choice : 4 You have selected Milk Shake Enter The Qty : 2 Do You want to continue press 1: 2 Total amount : 145 Thank You Come Again
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions