![]() |
|
#1
|
|||
|
|||
Function creating helpDisclaimer: this is a homework assignment.
I am trying to write a program for an imaginary widget producing company. Each month, Widget Co. produces 123 new widgets from its production line during a good month, but only 52 widgets from its production line during a bad month. In addition, each month, its sales team takes orders for some number of widgets. If they are on-hand, Widget Co. reduces its inventory of widgets. If not on-hand, it compiles a back-order for the requested widgets. In order to receive full credit, you must use functions for this calculation and pass parameters and work with return values. The program should produce this when executed: Welcome to Widget Co.! Month: 0 Number of widgets on-hand: 0 Number back-ordered: 0 Was it a good or bad month (g/b)? How many did the sales force sell? Continue(y/n)? y If you continue to press Y it should increment each month and continue calculating the number of widgets produced, sold, and on back order. This is what I have so far: CPP / C++ / C Code:
I get 2 errors so far. On line 4 my compiler complains I have too many arguments in my function. On line 14 it says at this point in file, which is where I call my function so I figure if I alleviate the first error the second should disappear. I guess I have more parameters than have defined in the function, but I am not sure how else I could get what I want. Just looking for someone to point me in the right direction. I run on Windows XP Professional. My compile software is called Dev-C++. This is my second semester of programming. thanks Howard |
|
#2
|
||||
|
||||
Re: Function creating helpHoward,
You are thinking along the right track. Each time you refer to widget_calculator you need to use the same number of arguments. With the way you are using it I would guess you just need one, an integer for passing the number of widgets on hand. Then you will also need to declare the other variables local to your widget_calculator function it its body. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#3
|
|||
|
|||
Re: Function creating helpWell I have modified my program where I don't get any compile errors. Now I just get a fatal logic error.
CPP / C++ / C Code:
When I run this modified version, it works fine for the first loop. But when you go into the second loop it produces results that I don't want. For instance, if you typed in "g" for the first month being good, and the sales team selling 15 widgets the end result for Number of Widgets on Hand for the next month will be 108. However when you type in 'B' for bad month and a sell of 150 widgets you get -91 on hand for the next month. I think the problem is that I have switched the order for my arguments I am not sure. I have been fiddling around with it for some time and can't seem to get the correct arrangement. thanks again Howard |
|
#4
|
|||
|
|||
Re: Function creating helpHi,
I would suggest one small change in your code : CPP / C++ / C Code:
You have been assigning a particular value for the variable (widgets1) everytime you call the loop and therefore the results were not what you expected when loop called after the first execution. Regards, Rajeev |
|
#5
|
||||
|
||||
Re: Function creating helpQuote:
CPP / C++ / C Code:
So what's 59 - 150? __________________
Age is unimportant -- except in cheese |
|
#6
|
|||
|
|||
Re: Function creating helpYour function prototype doesn't match with function call and function definition.
Please look at it. __________________
Linux is the best OS in the world. |
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Flex and bison coding | lucky88star | C++ Forum | 5 | 24-Dec-2007 11:57 |
| Need Help with input files. | Efferus | C++ Forum | 2 | 24-Nov-2007 16:19 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
| [Tutorial] Function Pointers | aaroncohn | C++ Forum | 4 | 17-Feb-2006 11:33 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The