Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- struct Item
- {
- string name;
- double price;
- int quantity;
- };
- void addItem(Item* shoppingCart);
- void listItems(Item* shoppingCart);
- void sumPrices(Item* shoppingCart);
- int main()
- {
- char choice;
- Item* shoppingCart = new Item[100];
- cout << "Shopping Cart is now available for use. \n";
- cout << "Please choose between the following choices: \n\n";
- cout << "1. Add Item: for adding new items to the cart\n";
- cout << "2. List Shopping Cart Contents: see what you have!\n";
- cout << "3. Total Price: how much does it add up to?\n";
- cout << "4. Quit: You're done here.\n";
- cout << "Please enter your choice now: \n";
- cin >> choice;
- switch (choice)
- {
- case '1': addItem(shoppingCart);
- break;
- case '2': listItems(shoppingCart);
- break;
- case '3': sumPrices(shoppingCart);
- break;
- case '4': cout << "Goodbye!\n";
- break;
- default: cout << "You did not enter a valid choice! \n";
- }
- return 0;
- }
- /************************************************
- * This is the addItem function *
- ************************************************/
- void addItem(struct Item* shoppingCart)
- {
- for(int i = 0; i < 100; i++)
- {
- cout << "Please enter the new item Name: \n";
- cin.ignore();
- getline(cin, shoppingCart[i].name);
- cout << "Please enter the new item Price: \n";
- cin >> shoppingCart[i].price;
- cout << "Please enter the new item Quantity: \n";
- cin >> shoppingCart[i].quantity;
- while(shoppingCart[i].name != " ");
- }
- return;
- }
- /************************************************
- * This is the listItems function *
- ************************************************/
- void listItems(struct Item* shoppingCart)
- {
- cout << fixed << showpoint << setprecision(2) << "\n";
- for(int i = 0; i < 100; i++)
- {
- cout << "Item " << i << " name: " << shoppingCart[i].name << ".\n";
- cout << "Item " << i << " price: " << shoppingCart[i].price << ".\n";
- cout << "Item " << i << " quantity: " << shoppingCart[i].quantity << ".\n";
- while (shoppingCart[i].name != " ");
- }
- return;
- }
- /************************************************
- * This is the sumPrices function *
- ************************************************/
- void sumPrices(struct Item* shoppingCart)
- {
- cout << fixed << showpoint << setprecision(2) << "\n";
- double sumTotal = 0.00;
- for(int i = 0; i < 100; i++)
- {
- sumTotal += (shoppingCart[i].quantity)*(shoppingcart[i].price);
- while(shoppingCart[i].name != " ");
- }
- cout << "Your total is: $" << sumTotal << " for items currently in your cart.\n";
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement