Hey guys this code is for a coffee machine. I am trying to add a operator mode for this machine.
#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";
cout<<"\nPress' 2' for operator mode\n\n";
int input;
cin>>input;
if (input==2)
{
cout << "Welcome to operator mode \n";
cout << "Press '1' for add more coffee powder \n";
cout << "Press '2' for exit\n";
int op;
cin >> op;
if(op==2){
return op;
}
}
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";
I've used a vector for this struct part.
vector<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 }
};
but after using this part my 'for loop' didn't work.. Could some one help me to 'cout' the vector part.
And also i need your help to make the operator mode.By operator mode operator should be able to add more coffee types and change the number of coffees in the machine..Below i have shown the code i got from one of the contributor in stackoverflow.But i dont know how to implement below code part to my code.
coffee entry;
cin >> entry.country
>> entry.itemprice
>> entry.country
>> entry.quantity;
drink.push_back(entry);
How to use above code to modify details in the struct(drink).