0% found this document useful (0 votes)
12 views2 pages

Order Placing 1

Uploaded by

Mohammad Ashar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Order Placing 1

Uploaded by

Mohammad Ashar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <vector>
#include <string>
#include <map> // For storing item prices

using namespace std;

struct Order {
string item;
int quantity;
double price;
};

// Function to display the order details


void displayOrder(const Order& order) {
cout << "Item: " << order.item << endl;
cout << "Quantity: " << order.quantity << endl;
cout << "Price per item: $" << order.price << endl;
cout << "Total cost: $" << order.quantity * order.price << endl;
}

int main() {
// Define prices for items
map<string, double> itemPrices = {
{"apple", 1.00},
{"banana", 0.50},
{"orange", 0.75}
// Add more items and prices as needed
};

vector<Order> orders; // Vector to store multiple orders

char choice;
do {
Order newOrder;
cout << "Enter item name: ";
cin >> newOrder.item;

// Check if the item exists in the itemPrices map


if (itemPrices.find(newOrder.item) == itemPrices.end()) {
cout << "Item not found. Please enter a valid item." << endl;
continue; // Skip the rest of the loop iteration
}

newOrder.price = itemPrices[newOrder.item]; // Set price based on item


cout << "Enter quantity: ";
cin >> newOrder.quantity;

orders.push_back(newOrder); // Add the order to the vector

cout << "Do you want to place another order? (Y/N): ";
cin >> choice;
} while (choice == 'Y' || choice == 'y');

// Display all the orders


cout << "\nOrders placed:\n";
for (const auto& order : orders) {
displayOrder(order);
cout << endl;
}

return 0;
}

You might also like