Answer to Question #228730 in C for Riya

Question #228730
an ecommerce company plans to give their customers a discount for the new year. the discount will be calculated on the basis of the bill amount is the product of the sum of all odd digits and the sum of even digits of the customer's total bill. if no odd-even digit is represented in the bill amount then 0 will be returned?
1
Expert's answer
2021-08-23T07:29:32-0400
#include<stdio.h>




int calculateDiscount(int billAmount){
	int bill_amount=billAmount;
	int sumOddDigits=0;
	int sumEvenDigits =0;
	while(bill_amount>0)    
	{    
		int digit=bill_amount%10; 
		if(digit%2==0){
			sumEvenDigits+=digit;
		}else{
			sumOddDigits+=digit;
		}
		bill_amount=bill_amount/10;    
	}  
	return sumOddDigits*sumEvenDigits;
}


int main(){
	int billAmount=0;
	int discount=0;
	int totalBill=0;


	printf("Enter the bill amount: ");
	scanf("%d",&billAmount);
	discount=calculateDiscount(billAmount);


	totalBill=discount+billAmount;
	printf("\nDiscount is: %d\n",discount);
	printf("The total bill is: %d\n",totalBill);






	scanf("%d",&billAmount);
	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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS