I have most of the program done but need some help with getting the program to:
Get the price of an item by its name.
Get the quantity of an item by its name.
Get the average price of all items.
Here's my code:
Code:#include <iostream> #include <stdlib.h> using namespace std; struct ItemDataType { char name[30]; int price; //Price in cents int quantity; //Number in inventory }; ItemDataType ReadEntry(); int main () { ItemDataType Item[100]; int TotalItem; int index; cout << "How many items are there? "; cin >> TotalItem; for (index = 0; index < TotalItem; index++) { Item[index] = ReadEntry(); } bool done = false; char userChoice; while (!done) { cout << "Please select a choice\n"; cout << "1: Get price by name\n"; cout << "2: Get quantity by name\n"; cout << "3: Get the average price\n"; cout << "4: Exit\n"; cin >> userChoice; switch (userChoice) { case '1' : GetPriceByName(Item, TotalItem); break; case '2' : GetQuantityByName(Item, TotalItem); break; case '3' : GetAveragePrice(Item, TotalItem); break; case '4' : done = true; break; default : cout << "Invalid selection, please try again\n\n"; break; } } cout << "Goodbye\n"; return 0; } ItemDataType ReadEntry() { ItemDataType Data; cout << "Enter item name: "; cin >> Data.name; cout << "Enter item price in cents: "; cin >> Data.price; cout << "Enter item quantity: "; cin >> Data.quantity; return Data; }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.