首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >商店产品- Arduino上的数据库

商店产品- Arduino上的数据库
EN

Stack Overflow用户
提问于 2018-06-06 04:48:13
回答 1查看 132关注 0票数 1

我想为我在控制整个机器的Arduino上构建的自动售货机存储产品。在Python中,你可以通过字典来做到这一点:

ID:价格、名称、数量

products = {
    1: [1.09, "Coke", 0.33],
    2: [0.71, "Coke Zero", 0.33],
    3: [0.44, "Water", 0.5],
    4: [1.09, "Sprite", 0.33]
}

但是我不知道怎么做,Arduino / C++。有没有人帮我?

而且也没有if ID in products。我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-06 05:18:25

不确定Arduino支持什么,不支持什么,也许可以尝试一下这样的东西,看看它是否有效:

struct Product
{
    float price;
    char const *name;
    float volume;
};

Product const products[4] =
{
    { 1.09, "Coke", 0.33 },
    { 0.71, "Coke Zero", 0.33 },
    { 0.44, "Water", 0.5 },
    { 1.09, "Sprite", 0.33 }
};

然后你可以把你的产品称为

products[0].nameproducts[0].priceproducts[0].volume等。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50708707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档