You have to write a menu-driven programme to create a bill for the item(s) selected by the user.
Keep asking the user for selecting available items with their price list until the user inputs ‘N’ for No.
Do this with the help of while loop and switch statement. Finally, you have to display the bill amount
of all those selected items.
#include<stdio.h>
int main(){
int n;
int i=1;
float price;
float billAmount=0;
char answer='y';
while(answer=='y' || answer=='Y'){
printf("Enter the price of item %d: ",(i));
scanf("%f",&price);
billAmount+=price;
fflush(stdin);
printf("Do you want to select other item (y/n): ");
scanf("%c",&answer);
switch(answer){
case 'y':
case 'Y':
break;
case 'n':
case 'N':
answer='n';
break;
}
i++;
}
printf("\n\nThe bill amount of all selected items: %.2f\n\n",billAmount);
scanf("%d",&n);
return 0;
}
Comments
Leave a comment