- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用从文件中收集的信息为一个小型拍卖系统用 C 语言编写了这个程序。拍卖系统应存储出价,将起始出价/最低增加出价应用于列表,然后通过菜单系统显示结果。我相信我已经实现了项目的目标,但我现在正在尝试简化我的代码。
我不确定我的代码是否完全正确,或者是否有更简单的方法使用更少的代码来布局信息。任何提示也将不胜感激!感谢您的宝贵时间。
输入文件看起来像这样
500 40
100 20
20 7
300 55
700 120
其中第一个数字是“拍卖起拍价”
第二个数字是“拍卖最低增幅”
#include<stdio.h>
#include<stdlib.h>
//int main
int main() {
//open input text
FILE * ifp;
ifp = fopen("input.txt", "r");
printf("Welcome to the Silent Auction\n");
printf("\nPlease make a selection from the following:\n");
int number = 1;
int starting_bid1 = 0;
int starting_bid2 = 0;
int starting_bid3 = 0;
int starting_bid4 = 0;
int starting_bid5 = 0;
int au1_start, au1_min, au2_start, au2_min, au3_start, au3_min, au4_start, au4_min, au5_start, au5_min;
char choice [20];
fscanf(ifp, "%d %d", &au1_start, &au1_min);
fscanf(ifp, "%d %d", &au2_start, &au2_min);
fscanf(ifp, "%d %d", &au3_start, &au3_min);
fscanf(ifp, "%d %d", &au4_start, &au4_min);
fscanf(ifp, "%d %d", &au5_start, &au5_min);
printf("\nView Auctions [VIEW]\nBid on an Auction [BID]\nClose Auctions [CLOSE]\n");
scanf("%s", &choice);
if (strcmp(choice, "VIEW", "view", "View") == 0) {
printf("\nNumber Current Bid Minimum Increase\n");
if (starting_bid1 < au1_start){
printf("1 $%d $%d\n", starting_bid1, au1_start);
}
else{
printf("1 $%d $%d\n", starting_bid1, au1_min);
}
if (starting_bid2 < au2_start){
printf("2 $%d $%d\n", starting_bid2, au2_start);
}
else{
printf("2 $%d $%d\n", starting_bid2, au2_min);
}
if (starting_bid3 < au3_start){
printf("3 $%d $%d\n", starting_bid3, au3_start);
}
else{
printf("3 $%d $%d\n", starting_bid3, au3_min);
}
if (starting_bid4 < au4_start){
printf("4 $%d $%d\n", starting_bid4, au4_start);
}
else{
printf("4 $%d $%d\n", starting_bid4, au4_min);
}
if (starting_bid5 < au5_start){
printf("5 $%d $%d\n", starting_bid5, au5_start);
}
else{
printf("5 $%d D $%d\n", starting_bid5, au5_min);
}
}
else if (strcmp(choice, "BID", "bid", "Bid") == 0) {
printf("\nWhich auction would you like to bid on?\n");
scanf("%d", &number);
switch (number) {
case 1:
printf("The minimum bid is $%d.\n", au1_start);
printf("How much would you like to bid?\n");
scanf("%d", &starting_bid1);
if (starting_bid1 < au1_start){
printf("Sorry, that bid is not high enough.\n");
}
break;
case 2:
printf("The minimum bid is $%d.\n", au2_start);
printf("How much would you like to bid?\n");
scanf("%d", &starting_bid2);
if (starting_bid2 < au2_start){
printf("Sorry, that bid is not high enough.\n");
}
break;
case 3:
printf("The minimum bid is $%d.\n", au3_start);
printf("How much would you like to bid?\n");
scanf("%d", &starting_bid3);
if (starting_bid3 < au3_start){
printf("Sorry, that bid is not high enough.\n");
}
break;
case 4:
printf("The minimum bid is $%d.\n", au4_start);
printf("How much would you like to bid?\n");
scanf("%d", &starting_bid4);
if (starting_bid4 < au4_start){
printf("Sorry, that bid is not high enough.\n");
}
case 5:
printf("The minimum bid is $%d.\n", au5_start);
printf("How much would you like to bid?");
scanf("%d", &starting_bid5);
if (starting_bid5 < au5_start){
printf("Sorry, that bid is not high enough.\n");
}
default:
printf("\n");
}
}
else if (strcmp(choice, "CLOSE", "close", "Close") == 0) {
if (starting_bid1 >= au1_start){
printf("\nAuction 1 sold for %d.\n", starting_bid1);
}
else{
printf("\nAuction 1 did not sell.\n");
}
if (starting_bid2 >= au2_start){
printf("Auction 2 sold for %s.\n", starting_bid2);
}
else{
printf("Auction 2 did not sell.\n");
}
if (starting_bid3 >= au3_start){
printf("Auction 3 sold for %s.\n", starting_bid3);
}
else{
printf("Auction 3 did not sell.\n");
}
if (starting_bid4 >= au4_start){
printf("Auction 4 sold for %s.\n", starting_bid4);
}
else{
printf("Auction 4 did not sell.\n");
}
if (starting_bid5 >= au5_start){
printf("Auction 5 sold for %s.\n", starting_bid5);
}
else{
printf("Auction 5 did not sell.\n");
}
}
else{
printf("\nPlease choose either VIEW, BID, or CLOSE.\n");
}
// formatting
printf("\n");
//close file
fclose(ifp);
//return main
return 0;
}
粗体代表用户输入
最终产品应该是这样的:
Welcome to the Silent Auction
Please make a selection from the following:
View Auctions [VIEW]
Bid on an Auction [BID]
Close Auctions [CLOSE]
查看
Number Current Bid Minimum Increase
1 $0.00 $500.0
2 $0.00 $100.00
3 $0.00 $20.00
4 $0.00 $300.00
5 $0.00 $700.00
Please make a selection from the following:
View Auctions [VIEW]
Bid on an Auction [BID]
Close Auctions [CLOSE]
出价
Which auction would you like to bid on?
3
The minimum bid is $20.00.
How much would you like to bid?
21
Please make a selection from the following:
View Auctions [VIEW]
Bid on an Auction [BID]
Close Auctions [CLOSE]
关闭
Auction 1 did not sell.
Auction 2 did not sell.
Auction 3 sold for $21.00!
Auction 4 did not sell.
Auction 5 did not sell.
最佳答案
你少了一个逗号:
fscanf(ifp, "%d %d", &au1_start &au1_min);
应该是
fscanf(ifp, "%d %d", &au1_start, &au1_min);
显然编译器将其解析为 (&au1_start) & au1_min
,第二个 &
被解释为二进制 &
(按位与)运算符,因此警告,由于到不匹配的数据类型。
关于c - C 中的简单拍卖系统 - 提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15776961/
我的 friend 编写了一个程序,它比较随机排列的骰子面,以找到分布最均匀的面——尤其是当面不仅仅是序列时。 我将他的程序翻译成 haskell 是因为我一直在寻找一个理由来让别人知道 haskel
我需要对表单中的某些字段进行评论/提示。我的想法是在模型中描述它,就像attributeLabels一样。我该怎么做? 然后它会是理想的,如果 Gii 模型(和 Crud)生成器直接从 mysql 列
我们使用 FastReport 来生成报告。事实上,我们为访问源代码付费。 我们目前使用的是 FastReport 的最新稳定版本。虽然它对于我们的生产来说足够稳定,但每当我编译时,我都会看到以下内容
我需要创建一个对话框/提示,包括用于用户输入的文本框。我的问题是,确认对话框后如何获取文本?通常我会为此创建一个类,将文本保存在属性中。不过我想使用 XAML 设计对话框。因此,我必须以某种方式扩展
我想提示用户是否要执行操作(删除) - 用警报框说"is"或“否”,如果是,则运行删除脚本,如果否,则不执行任何操作 我不太了解 javascript,因此是否有人可以使用 javascript 获得
所以我正在编写一个简单的 JS 代码。我们刚刚开始学习函数。我需要创建一个名为“printStars”的函数。 我需要从用户那里获取一个号码,并根据该号码打印“*”。 这就是我所做的:
我在我的页面上添加了一个提示,但它在页面加载之前加载了。如何仅在整个页面可见时才显示消息? 这是我的提示: if (name == null || name == "") { txt == "No
我在我的页面上添加了一个提示,但它在页面加载之前加载了。如何仅在整个页面可见时才显示消息? 这是我的提示: if (name == null || name == "") { txt == "No
我正在自定义我的 zsh 提示,并发现以下内容来检查是否有任何后台作业: if [[ $(jobs | wc -l) -gt 0 ]]; then # has background job(s)
这个问题在这里已经有了答案: JavaScript object: access variable property by name as string [duplicate] (3 个答案) pa
我正在尝试用 javascript 制作一个简单的数学练习程序。在提示警报中给出不同的值,并将答案与用户输入进行比较。这是代码: Calculations generate(); functio
在这段代码中,尽管我使用了文本对齐属性在“编辑文本” View 的中心设置“提示”。但它无法正常工作。 最佳答案 尝试 关于android - 如何在编辑文本的中心对齐文本(提示),我们在Sta
我正在尝试让我的 EditText 显示一个提示,例如“请在此处输入答案”,当用户点击 EditText 以键入他们的答案时,文本应该消失并留空,以便他们在其中输入答案. 截至目前,这就是我的 .xm
我当前的 android 应用程序中有两个微调器,我想要一个默认值,例如 editText 的 android:hint 功能。有没有办法这样做,但不会将提示添加到填充微调器的字符串数组。例如从微调器
如果我的表单已完全填写,我如何提示“感谢您填写表单,“name”!” function submit_onclick() { if(confirm("Thanks for completing t
我刚刚了解了prompt()命令;我知道 Prompt() 命令以字符串的形式返回用户输入。我正在搞乱下面的程序,我输入了Per“Dead”Ohlin作为男性名字。为什么这有效并且没有引起任何问题?
void openUpNow(FILE *x, FILE *y) { x = fopen("xwhatever", "r"); y = fopen("ywhatever", "r");
我有一个作业正在处理,但我在使用 prompt() 方法时遇到了问题。我看到我可以做一个提示,但我需要几个并且有数量。 例如... 我创建了一个 HTML 表格,其中包含许多艺术家和包含 DVD、CD
我正在学习 Big Nerd Ranch 的 iOS Programming, 2nd Edition,我已经来到第 4 章挑战:标题。该练习暗示我感到困惑;它说我需要做一些我认为不需要做的事情。 到
抱歉,如果这是微不足道的,但我没有找到任何解决此问题的建议。我在 Ubuntu 上,我的 Yii 项目需要 PHPUnit。我已经安装了 PHPUnit 两次,方法是下载 phpunit.phar 并
我是一名优秀的程序员,十分优秀!