c++ - 如何从我的咖啡机获取销售报告(每日销售)?
问题描述
嘿,下面的代码部分是一个简单的咖啡机。人们可以随时购买咖啡。这里我想在按下“离开机器”(No.8)后获得销售报告。例如,如果客户购买了 3 杯浓缩咖啡和 5 杯拿铁咖啡在我按下“离开机器”时,它必须显示该详细信息。(咖啡名称、数量和从该销售中收取的总金额)。有人可以帮我解决这个问题吗?
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct coffee {
string name;
int itemprice;
string country;
int quantity;
};
float remainder, price2, price;
int main() {
int coffeetype = 1;
cout<<"\nPress'1'for buy a coffee\n";
coffee drink[] = {
{ "Espresso", 120, "Italy", 20 },
{ "Iced coffee", 150, "France", 20 },
{ "Long black", 80, "Austral", 20 },
{ "Americano", 100, "America", 20 },
{ "Latte", 200, "Italy", 20 },
{ "Irishcoffee",130, "Ireland", 20 },
{ "Cappuccino", 180, "Italy", 20 }
};
cout << fixed;
cout << setprecision(2);
cout<<"Enter the name of coffee";
while(coffeetype != 8){
for (int i = 0; i != sizeof(drink)/sizeof(drink[0]); ++i)
cout<< "\n " << i+1 << ") "<<drink[i].name<<"\t\t"<<drink[i].itemprice<<"\t\t"<<drink[i].country<<"\t\t("<<drink[i].quantity<<") remaining";
cout<<"\n 8) Leave the drink machine \n\n";
cout<<"\n Choose one:";
cin >> coffeetype;
}
}
解决方案
int nKindNumb[7] = { 0 };
while (coffeetype != 8) {
for (int i = 0; i != sizeof(drink) / sizeof(drink[0]); ++i)
cout << "\n " << i + 1 << ") " << drink[i].name << "\t\t" << drink[i].itemprice << "\t\t" << drink[i].country << "\t\t(" << drink[i].quantity << ") remaining";
cout << "\n 8) Leave the drink machine \n\n";
cout << "\n Choose one:";
cin >> coffeetype;
if (coffeetype < 8 && coffeetype >= 1)
{
nKindNumb[coffeetype - 1]++;
}
}
int nSum = 0;
for (int i = 0; i < 7; i++)
{
if (nKindNumb[i] != 0)
{
cout << "\n \tName: " << drink[i].name << "\t Quantity: " << nKindNumb[i] << "\t Total-price: " << drink[i].itemprice * nKindNumb[i];
nSum += drink[i].itemprice * nKindNumb[i];
}
}
cout << "\n \tTotal-price: " << nSum;
cout << "\n";
希望这可以帮助
推荐阅读
- firebase - 在 Flutter 中播放来自 Firebase 存储的 .m3u8 视频
- ios - 以编程方式显示到控制器的导航
- javascript - Vue 3 上的路由器视图无法捕获来自子级的事件
- r - 以特殊方式获取长格式
- python - 学生ID的数据框组
- java - 我创建了一个类,我还想创建一个接口来插入值而不是代码本身。我怎样才能做到这一点?
- python - Mass DM 机器人工作正常,现在它不会发送消息
- tensorflow - 如何连接两个在一个维度上大小相同但在另一个维度上大小不同的张量流张量?
- flutter - 当应用程序热重启时,列的子项的长度加倍
- django - 我应该为每个页面创建一个应用程序吗?(姜戈)