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?

Expert's answer

#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;
}






LATEST TUTORIALS
APPROVED BY CLIENTS