Not liking C++

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?
What is a module? A file? A function?
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

Here is your main program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

#include "factorial.h"

int main(int nNumberofArgs, char* pszArgs[])
{
    cout << "This program calculates factorials"
    << " of a user input.\n"
    << "Enter a negative number to exit" << endl;

    for (;;)
    {
        int nValue;

        cout << "Enter number: ";
        cin >> nValue;

        if (nValue < 0)
        {
            break;
        }

        int nFactorial = factorial(nValue);
        cout << nValue << " factorial is "
        << nFactorial << endl;
    }

    system("PAUSE");
    return 0;
}


Here is your function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// factorial - this module includes the factorial function
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
#include "factorial.h"

// 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;
    }

    return nAccumulator;
}


Here is the header that links the function and main program together

1
2
3
4
5
6
7
#ifndef FACTORIAL_H_INCLUDED
#define FACTORIAL_H_INCLUDED

int factorial(int nTarget);

#endif // FACTORIAL_H_INCLUDED


Does this help?

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.
randisking, and Veltas, lol just give him the answer...

Belyvr, use my example and build off of it. You need headers to transfer information
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.
LOL, couldn't you guys give him examples such as what I did? Discover how to do it from other's work. That's what taking notes is for.
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.
Ok
Topic archived. No new replies allowed.