Need some help im working on a class project and am having trouble getting the data to transfer between modules for example in one module calculate the mean and then the next calculate the median. I have a bubble sort that works solo and a median that works solo but am having trouble mixing all the data between functions How do I marry the three, user input, mean and median in separate modules any suggestions?
Module's are module's, a group of stuff. They simplify your programs.
First: Make an int main()
Second: Get a function such as "Idosomething(char something)"
Third: Make a new c++ source
Fourth: In the source, under the #include...Make a #include "something"
Remember the "..." instead of <...> for user made includes
Fifth: Make a new c++ header and name it something.h
// factorial - this module includes the factorial function
// factorial - return the factorial of the argument
// provided. Returns a 1 for invalid arguments
// such a negative numbers
int factorial(int nTarget)
int nAccumulator = 1;
for (int nValue = 1; nValue <= nTarget; nValue++)
nAccumulator *= nValue;
Here is the header that links the function and main program together
1 2 3 4 5 6 7
int factorial(int nTarget);
#endif // FACTORIAL_H_INCLUDED
The beauty of C++ is sometimes also a barrier to beginners. It is complex, but in its complexity lies flexibility and the capability to provide quite a bit of reusability to code that you might otherwise write over and over again in slightly variable ways. Instead of thinking about the separation of code as modules, I've found it easiest to think about each component as a black box. Something goes into the box. Then you need it to send something back out. Don't concern yourself at first with the how.
What I mean by that is, don't worry about how you need to program something to get the result (at first). Just worry about what you need. Then work in psuedocode. Figure out what steps you need to take to get the result. Once you know what steps you need to take, it's then just about learning how to make the code work for you, instead of feeling like you need to work for the code.
I know that's very general, but if you draw it out on paper (do a google search for UML for some ideas on how to accomplish this) and then write it out pretty much in sentence form, it'll start forming bit by bit. Learning the syntax of how to make it work takes time, but if you know what you need, and are willing to be patient with a good reference book (or google, because really the need to buy a reference book with an available internet connection is becoming less and less every year), C++ will eventually seem understandable enough. Good luck with this and I didn't add any code because Greenleaf's post was more than sufficient enough in that regard for the concepts, I just wanted to toss a pep talk and maybe some general advice in there.
What's the fun in that. The joy of programming is the discovery. Plus you don't really learn just by being handed the answer. And I felt your answer was good enough that it didn't really need to be added onto.
I'm not going to sit and argue with you, as I said the first time, there was nothing code wise to add, I just felt like offering some general advice to go along with your example. Get over it already, I'm sure he's already moved on.