1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
#include <string>
#include <vector>
int main()
{
struct product
{
std::string tag;
std::string name;
double price;
// Constructor
product(std::string _tag, std::string _name, double _price)
{
tag = _tag;
name = _name;
price = _price;
}
};
std::vector<product> products
{ {"A31", "Mountain Dew", 2.99},
{"B32", "Coke", 3.99},
{"C33", "Dr. Bob", 9.99},
{"D34", "Diet Coke", 3.99},
{"E35", "Pepsi", 3.99},
{"F36", "Weed Cola", 1.99},
{"A21", "Mountain Dew Baja Blast", 2.99},
{"B22", "Myspac drink", 0.99},
{"C23", "Bottled Water", 0.99},
{"D24", "Talabrew", 5.99},
{"E25", "Mug Rootbeer", 1.99},
{"F26", "Dr.Perky", 2.99 } };
double money{ 15 };
std::string input;
std::cout << "Welcome to the Froggy Vendor. What would you like to purchase? (You have $" << money << " Currently in your balance.)\n";
std::cin >> input;
for (int i=0; i<products.size(); i++)
if (products[i].tag == input)
{
std::cout << "You ordered a " << products[i].name << '\n';
break;
}
}
|