Как получить отчет о продажах (ежедневные продажи) с моей кофемашины? - PullRequest
0 голосов
/ 26 мая 2020

Привет, следующая часть кода предназначена для простой кофемашины. Люди могут покупать кофе в любое время. Здесь я хочу получить отчет о продажах после нажатия кнопки «Оставить машину» (№ 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;
    }
}

1 Ответ

1 голос
/ 26 мая 2020
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";

надеюсь, это поможет

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...