收银机程序-C
你好!在我为学校写的一个程序中,我们必须制作一个收银机类型的程序,看起来很简单,但就我的生活而言,我无法让它工作。在拿到购买的产品数量后,再计算所有产品的价格,程序必须要求现金支付,然后退还找零。但零钱必须以面值(或1美元钞票)的形式支付,然后再支付剩下的美分。帮忙?我已经让疯子们开始工作了(有点),但我不知道该如何做改变收银机程序-C,c,C,你好!在我为学校写的一个程序中,我们必须制作一个收银机类型的程序,看起来很简单,但就我的生活而言,我无法让它工作。在拿到购买的产品数量后,再计算所有产品的价格,程序必须要求现金支付,然后退还找零。但零钱必须以面值(或1美元钞票)的形式支付,然后再支付剩下的美分。帮忙?我已经让疯子们开始工作了(有点),但我不知道该如何做改变 #include <stdio.h> #include <stdlib.h> int main() { int itemNum, justC
#include <stdio.h>
#include <stdlib.h>
int main()
{
int itemNum, justChange;
double prodPrice, tax, cashGiven, change, purchasePrice, changeGiven, changeBack, cashBack;
float totalPrice;
//Num of items
printf ("Number of items: ");
scanf("%d", &itemNum);
//Price of items
printf("Please enter price of items: ");
scanf("%lf", &prodPrice);
//Math Stuff
purchasePrice = itemNum*prodPrice;
tax = purchasePrice * 0.13;
totalPrice = purchasePrice*1.13;
//find change alone
//justChange = totalPrice
//Price Output
printf("Purchase price is: %.2lf \n",purchasePrice );
printf("TAX (HST 13%): %.2lf\n",tax );
printf("Total price is: %.2lf \n",totalPrice );
printf("Please Enter Cash: ");
scanf("%lf", &cashGiven);
printf("Please Enter Change: ");
scanf("%lf", &changeGiven);
//MAth stuuff again
double endCash;
double loony;
int yoloswag;
endCash = cashGiven - totalPrice;
loony = endCash/1;
loony = loony--;
if (loony<0)
printf ("Loonies: 0");
else
printf("Loonies: %.0lf \n",loony );
printf("change: %d ", totalPrice-floor(totalPrice) );
return 0;
}
#包括
#包括
int main()
{
int itemNum,justChange;
double prodPrice,tax,cashGiven,change,purchasePrice,changeGiven,changeBack,cashBack;
浮动总价格;
//项目数
printf(“项目数量:”);
scanf(“%d”和&itemNum);
//物品价格
printf(“请输入项目价格:”);
scanf(“%lf”、&prodPrice);
//数学知识
purchasePrice=itemNum*prodPrice;
税=购买价格*0.13;
总价=购买价*1.13;
//独自寻找改变
//justChange=总价
//价格产出
printf(“采购价格为%.2lf\n”,采购价格);
printf(“税(HST 13%):%.2lf\n”,税);
printf(“总价为%.2lf\n”,总价);
printf(“请输入现金:”);
scanf(“%lf”,&cashGiven);
printf(“请输入更改:”);
scanf(“%lf”,&changeGiven);
//又是数学史杜夫
双端现金;
双重疯狂;
内特约洛斯瓦格;
endCash=cashGiven-总价;
loony=endCash/1;
疯癫=疯癫--;
如果(loony创建一个具有可能变化值的数组
double cashValues[6] = {1, 0.5, 0.2, 0.1, 0.05, 0.01};
然后创建一个for循环,尝试从差值中减去可能的更改值,直到差值为零
double difference;
difference = cashGiven - totalPrice;
while (difference != 0) {
for(int i=0; i<6; i++) {
if(cashValues[i] <= difference) {
difference -= cashValues[i];
printf("%f \n", cashValues[i]);
i=0;
}
}
}
双差;
差额=给定现金-总价;
while(差!=0){
对于(int i=0;如果对于某些特定的输入,预期输出和实际输出是什么?@JoachimPileborg输入要支付的现金,然后在一行中返回输出更改,表示要返回的金额为1,在下一行中,剩余的美分更改。我没有得到错误的输出,我只是不确定如何显示剩余的更改