![]() |
problem with user defined class mixed with functions
Hi, I am a beginner in C++ programming. Not only am I new to the language, I only recently registered with this website; so please bear with me.
My question is rather lengthy: I am trying to create a program for my college C++ class that keeps an inventory for a very simple convenience store. It only sells 5 things: gas, beer, soda pop, candy and chips. Each item has its own price. My job is to write an inventory tracking program so that as a customer comes through, I can track how much a customer owes and track home much inventory I have. I need to: 1. Print the initial inventory. Printing of the inventory should be done in tabular format, with all items lining up in columns. 2. Prompt the user for the quantity of a product to buy. The program will print the price of the item to the user. 3. Continue prompting until the user finishes. The program will print the updated inventory. I also need to: create a class "inventory", which contains the quantity of each of the five items (as an integer) and the price of each of the five items (as a double). The requirements are basically to have a user defined class, use a switch statement somewhere in the code, and to have 7 functions. The functions purposes and their declarations are: 1. Inventory int(int,double,int,double,int,double,int,double,int,double). This function takes in the initial quantities and the price for each of the 5 items. It returns an Inventory. 2. void report (Inventory). This function provides a report of the present inventory. This includes the quantity and price of each item and the total worth of the present inventory. 3. Inventory gas (Inventory, int). This function takes in an Inventory and a quantity of gas. It then provides a price message to the customer and updates the Inventory. It returns the updated Inventory. 4. Inventory pop (Inventory, int). Same as above but for soda pop. 5. Inventory beer (Inventory, int). Same as above but for beer. 6. Inventory candy (Inventory, int). Same as above but for candy. 7. Inventory chips (Inventory, int). Same as above but for chips Classes and function are new things to me. I don't completely understand them. Now here's my problem: Although I'm not exactly sure what the problem is, I know the problem lies in either the class definition, the function call, or the function definition. Everytime I run, the errors are: 'gas': cannot convert parameter 1 from 'int' to 'inventory'. ---- regarding the function call 'gas': local function definitions are illegal.----regarding the function definition. I know my question isn't specific, and I'm basically asking you to "make it work somehow". But if I know how to do just the first function, (gas function takes in an inventory and a quantity of gas. It then provides a price message to the customer and updates the Inventory. It returns the updated Inventory. ) I could probably do the rest. :
#include<iostream> |
Must.. tell... user... use... [code]... tags...
(please use [code] tags around your code when you post it so it doens't look like a bunch of hard to read crap) If you repost with [code] tags i'll read your code and help you out. |
Sorry, but what do you mean by code tags? Comments in my code to guide you?
|
No, click the "Go Advanced" button if you are in the "Quick Reply" area.
Find the button on it that looks like "#". Paste your code into the box, select it, and the hit that button ("#"). Then post. |
The first thing you can't do is define a function inside another function. That's what this message is telling you:
Quote:
Fix that, and come back if you're still fuzzled. |
| All times are GMT -5. The time now is 4:23 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC