急急急!编写一个找零钱的程序(C++编程题)
发布网友
发布时间:2023-11-20 00:57
我来回答
共1个回答
热心网友
时间:2024-11-23 21:26
#include <stdio.h>void main() {
int i,payout,papmoney,tmp = 0;
int papermoneys[] = {50,20,10,5,2,1};
printf("输入找零钱数:");
scanf("%d",&payout);
if((payout<= 0)||(payout >= 100)) return;
for(i = 0;i < 6;i++) {
papmoney = (payout - (payout % papermoneys[i]))/papermoneys[i];
if (papmoney > 0) {
printf("\n应找回%d元券%d张",papermoneys[i],papmoney);
tmp = tmp + papmoney*papermoneys[i];
payout = payout - papmoney*papermoneys[i];
}
}
printf("\n\n共计:%d元。\n\n",tmp);
}