首页 > 解决方案 > 如何从我的咖啡机获取销售报告(每日销售)?

问题描述

嘿,下面的代码部分是一个简单的咖啡机。人们可以随时购买咖啡。这里我想在按下“离开机器”(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;
    }
}

标签: c++struct

解决方案


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";

希望这可以帮助


推荐阅读