#include <iostream>using namespacestd;#definePrice 8Doublediscount[5]={0,0.05,0.1,0.2,0.25};DoubleCaculate (intNUM1,intNUM2)//calculate the price of the case{ DoubleMoney,money1,money2; Money1= (price-price*discount[num1-1])*NUM1; Money2= (price-price*discount[num2-1])*num2; Money=money1+Money2; returnMoney ;}DoubleDiscount (intNum//discuss the price of the situation{ intK,yushu; Doublemoney1,money2,min; K=num/5;//take the wholeyushu=num%5;//Take surplusmin=num*Price ; Switch(k) { Case 0: Money1= (price-price*discount[num-1])*num; Break; default: if(yushu==0) {Money1= (price-price*discount[4])*num; returnMoney1; } for(intI=1;i< (yushu+5); i++) {Money1=caculate (i, (yushu+5)-i); if(money1<min) min=Money1; } if(num>9) Money2= (K-1)*5* (price-price*discount[4]); ElseMoney2=0; returnmin+Money2; } returnMoney1;}intMainintargcChar*argv[]) { intBooknum; DoubleMoney ; cout<<"Please enter the number of books purchased:"; CIN>>Booknum; Money=Discount (Booknum); cout<<"The most favorable price is"<<money<<"Yuan"<<Endl; return 0;}
Ask for the lowest price