Answer to Question #295535 in C for Sonu Rathore

Question #295535

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.

1
Expert's answer
2022-02-09T08:51:03-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment