- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的程序是一个购物车程序,它接收 UPC(商品 ID)、数量/重量并计算最终价格。该程序必须打印出所有购买元素的收据。
产品列表:
UPC Description PST PPT CIL
4011 BANANAS 1 0.49 123.2
4383 MINNEOLAS 1 0.79 187.3
3144 TANGERINES 1 1.19 135.5
4028 STRAWBERRIES_PINT 0 0.99 104
4252 STRAWBERRIES_HALF_CASE 0 3.99 53
4249 STRAWBERRIES_FULL_CASE 0 7.49 67
UPC 是项目代码PST 确定商品是按单位还是按重量出售PPT 是单价/重量CIL是库存(与本题无关)
这些值存储在并行数组中。
程序:
#include<stdio.h>
#include<stdlib.h>
/*
Description: This program will simulate a checkout at a grocery store. User will input
a UPC (item id) and a wieght/unit. The program will use parallel arrays to store these
values and output a final price at the end.
*/
int main(){
int upc[6] = { 4011, 4383, 3144, 4028, 4252, 4249 };
char desc[6][25] = {
"BANANAS ",
"MINNEOLAS ",
"TANGERINES ",
"STRAWBERRIES_PINT ",
"STRAWBERRIES_HALF_CASE",
"STRAWBERRIES_FULL_CASE" };
int upcR[6] = {};//storage array for reciept
float pptR[6] = {};//storage array for reciept
char descR[6][25] = {};//storage array for reciept
int pst[6] = { 1, 1, 1, 0, 0, 0 };
float ppt[6] = { 0.49, 0.79, 1.19, 0.99, 3.99, 7.49 };
float stock[6] = { 123.2, 187.3, 135.5, 104, 53, 67 };//AKA CIL or Current Inventory Level
float quant[6] = {};
float price[6] = {};
int option;
do
{
printf("Welcome! Enter 1 to begin or 0 to exit.\n");
scanf_s("%d", &option);
if (option == 1){
float subtotal = 0;
float total = 0;
float quantity;
float discount1 = 0;
float discount2 = 0;
float tax = 0;
int input;
int element = -1; //element/row number
do
{
printf("Enter UPC item code or enter 0 to start a new purchase.\n");
scanf_s("%d", &input);
if (input == 0)
break;
for (int i = 0; i < 6; i++)//Searches for element in parallel array using UPC
{
if (upc[i] == input)
{
element = i;
break;
}
}
if (element == -1){ // checks to see if UPC is valid
printf("Invalid UPC. Please try again.\n");
continue;
}
if (pst[element] == 1)// checks if product is sold by units or weight
{
printf("Weight: ");
scanf_s("%f", &quantity);
quant[element] = quantity;//stores elements for reciept array
price[element] = quantity*ppt[element];//stores elements for reciept array
if (quantity > stock[element]){
printf("This item is not available in this quantity.\n");
continue;
}
}
else
{
printf("Units: ");
scanf_s("%f", &quantity);
if (quantity > stock[element]){
printf("This item is not available in this quantity.\n");
continue;
}
}
subtotal += quantity * ppt[element];
stock[element] -= quantity;
quant[element] = 10;//stores elements for reciept array
price[element] = quantity*ppt[element];//stores elements for reciept array
upcR[element] = upc[element];
pptR[element] = ppt[element];
descR[element][25] = desc[element][25];
} while (input != 0);
if (subtotal > 50) //5% discount for purchases over $50
{
discount1 = subtotal - (subtotal * 0.95);
}
int random = rand() % 10 + 1;
if (random == 1){//random 5% discount if random number generated is 1.
discount2 = subtotal - (subtotal * 0.95);
}
float discount = discount1 + discount2;//total 10% from >50 spent and/or random coupon
tax = subtotal*.0825;//tax
total = subtotal + tax - discount;
printf("\n\nUPC\tDescription\t\tPPT\tWeight/Units\tPrice\n");
for (int i = 0; i < 6; i++){
printf("%d \t", upcR[i]);
printf("%s \t", descR[i]);
printf("\t\t%.2f \t", ppt[i]);
printf("%.2f \t\t", quant[i]);
printf("%.2f \t\n", price[i]);
}
printf("\t\t\t\t\tSubtotal\t$%.2f\n", subtotal);
printf("\t\t\t\t\tDiscount\t$%.2f\n", discount);
printf("\t\t\t\t\tTax\t\t$%.2f\n", tax);
printf("\t\t\t\t\tTotal\t\t$%.2f\n", total);
}
else if (option == 0){
break;
}
else
printf("You have entered an invalid option.\n");
}
while (option != 0);
printf("\n\nUPC\tDescription\t\tPST\tPPT\tCIL\n");
for (int i = 0; i < 6; i++){
printf("%d \t", upc[i]);
printf("%s \t", desc[i]);
printf("%d \t", pst[i]);
printf("%.2f \t", ppt[i]);
printf("%.2f \t\n", stock[i]);
}
system("Pause");
return 0;
}
所以我一遍又一遍地输入 UPC 和数量,直到完成结帐。问题是我需要以某种方式将这些交易存储到一个数组中,以便我可以在结账后打印出收据。现在我有一个单独的数组用于每一列的收据,我正在将我 checkout 的每个元素设置到这个单独的数组中然后打印出来。这似乎效果不佳,因为 1) 我无法将 char 数组复制到 double 数组中,并且 2) 空数组全为 0,这是我不想要的。
有更好的方法吗?如果有的话,我想要有关如何将字符串从 char 数组复制到某个元素到另一个数组的建议,我稍后会处理 0。
程序示例如下:
Welcome! Enter 1 to begin or 0 to exit.
1
Enter UPC item code or enter 0 to start a new purchase.
4011
Weight: 12.1
Enter UPC item code or enter 0 to start a new purchase.
4028
Units: 4
Enter UPC item code or enter 0 to start a new purchase.
4383
Weight: 8.3
Enter UPC item code or enter 0 to start a new purchase.
0
UPC Description PPT Weight/Units Price
4011 0.49 10.00 5.93
4383 M 0.79 10.00 6.56
0 T 1.19 0.00 0.00
4028 0.99 10.00 3.96
0 S 3.99 0.00 0.00
0 7.49 0.00 0.00
Subtotal $16.45
Discount $0.00
Tax $1.36
Total $17.80
Welcome! Enter 1 to begin or 0 to exit.
0
UPC Description PST PPT CIL
4011 BANANAS 1 0.49 111.10
4383 MINNEOLAS 1 0.79 179.00
3144 TANGERINES 1 1.19 135.50
4028 STRAWBERRIES_PINT 0 0.99 100.00
4252 STRAWBERRIES_HALF_CASE 0 3.99 53.00
4249 STRAWBERRIES_FULL_CASE 0 7.49 67.00
Press any key to continue . . .
注意:最终数组不是收据,它只是一天结束时的库存。上面的数组是我需要帮助制作的收据。
最佳答案
当我用 {0};
替换 all 出现的 {};
时。它马上就跑了。
示例:
float quant[6] = {};
应该是:
float quant[6] = {0};
这是我得到的示例输出(你告诉我它缺少什么)
EDITS 以解决评论:
在代码的这个区域添加 if(upcR[] != 0)
分支:
for (int i = 0; i < 6; i++){
if(upcR[i] != 0)//add this condition test
{
printf("%d \t", upcR[i]);
printf("%s \t", descR[i]);
printf("\t\t%.2f \t", ppt[i]);
printf("%.2f \t\t", quant[i]);
printf("%.2f \t\n", price[i]);
}
}
而且,您分配 descR[] 的方式不正确。您不能使用 =
将一个字符串数组设置为与另一个字符串数组相等。在您的代码中进行以下更改:
// descR[element][25] = desc[element][25];
strcpy(descR[element], desc[element]);
经过这些更改,输出现在看起来像这样:
关于c - 从并行数组打印收据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26434787/
我一直在尝试学习Grails,但是我遇到了以下问题。我已经创建了四个域类(Receipts,Items,类别和所有者),并且为每个域类(ReceiptsController,ItemsControll
我正在构建一个销售点应用程序,我想打印一张收据。问题是我使用的打印机无法打印纯文本的任何图形,我在 javafx 中只能找到使用 Print API 打印节点或使用像 jasper 这样都包含图形的报
我正在 Swift 3.0 应用程序中实现应用程序内购买,因此我需要获取应用程序收据以根据 iTunes 商店对其进行验证。这是我获得收据的方式: func getReceipt() -> Data?
我想在我的数据库中保存非消耗品的 IAP 收据。我们有一个用于 IAP 恢复的两步下载机制。 使用 StoreKit 机制检索所有交易(包括收据)。 从所有收据(即这些收据背后的产品)列表中选择稍后要
我想验证 iOS 收据。 我想我会向 App Store 验证服务器发送收据(https://sandbox.itunes.apple.com/verifyReceipt 或 https://buy.
我需要打印具有相同产品数量等的销售订单的 POS 收据 在销售订单中,我创建了一个按钮“打印 POS 收据”。使用此按钮,我想触发一种方法,该方法打印出带有销售订单行的收据。 所以我需要找到创建 PO
我们现在有一个正在生产中的应用程序,它会将 IAP 收据发送到我们的服务器,这些收据显然太短,而且我们的服务器没有经过 apple 的验证。 Apple 正确验证的长收据长度为 3192。短收据长度均
我正在构建一个 iOS 应用程序,它提供我们网站已经提供的服务。这是一项基于订阅的服务,订阅后所有功能都会启用。为了让人们在应用程序上注册定期付款,我似乎必须通过 Apple 的应用程序内购买 API
我需要一种方法来捕获笔记本中打印的所有内容。 为什么? 我有一个 PHP 系统,有时我需要打印(php_printer) 一些发票,但这会花费很多纸张。 打印在后台发送,没有任何弹出窗口供用户确认。
我对此有点困惑。所以关注this approach我得到了包含一堆解密字段的 json。其中 original_purchase_date。 我需要的是跟踪在这个新版本免费之前是否购买了应用程序,我认
首先,我说的不是调用https://buy.itunes.apple.com/verifyReceipt/ ,相反,我要问的是如何验证来 self 们的一位用户的 iTuneStore 收据。 我们的
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
所以我要建立一个在线商店,我想向客户发送包含收据的订单确认。我搜索了一下,但我还没有设法创建任何东西。 这是我发现并尝试使用的东西,但没有成功创建任何东西。 所以 ajax 调用会将 cartCon
所以我要建立一个在线商店,我想向客户发送包含收据的订单确认。我搜索了一下,但我还没有设法创建任何东西。 这是我发现并尝试使用的东西,但没有成功创建任何东西。 所以 ajax 调用会将 cartCon
我正在尝试实现自动续订订阅。我的应用程序可以在不同的设备(Android、Web)上使用,因此我需要实现状态轮询技术,以便在 App Store 设法续订过期订阅时确认我的服务器。收据正在我的服务器上
我正在尝试验证来自 C++ 服务器的 iphone 收据(我有使用 base64 加密的收据,我正在根据苹果文档编写一个 json 对象,然后我打开一个到沙箱的套接字并发送一个 POST请求)。 服务
首先,这个问题与 iOS7+ 收据有关,因此所有关于 latest_receipt 和 latest_receipt_info 的问题/答案都不适用(因为它们已被弃用并且正在离开)。似乎关于在 SO
谁能告诉我如何使用 Exchange Web 服务 API 获取电子邮件正文、收据、发件人、抄送信息?我只知道如何获取主题。 ExchangeService service = new Exchang
有关服务器到服务器通知的 Apple 文档没有指定 cancellation_date 字段中的数据格式。我正在尝试为我的通知处理程序设置一些单元测试,但我不确定要将哪些数据放入我的模拟响应中。 我假
我正在尝试使用 Citizen CT-S651 热敏打印机从网络浏览器打印 HTML/CSS 媒体格式的收据。我们已经能够正确格式化收据,但问题是在打印收据后,打印机继续吐纸而不是在内容的末尾切割。
我是一名优秀的程序员,十分优秀!