So I'm a new programmer and I'm SO close to finishing this code.
I want to return an array from a function, and every thread that I've looked up has said I need to return the data as a pointer TO an array.
How is that done?
Also, I'm working with Bloodshed, so the line system ("pause"); has always been part of my normal routine. I've been told that this isn't the best method, and I should instead say:

cout << "Press any key, then the enter key, to continue" << endl;
cin >> j;

This method obviously only works if you hit a character key. What can you do to pause the process without commanding the system to "pause"?

The code is as follows:

using namespace std;

//Function Prototype
void Eccentricity(float, float);
//Inline Function Definition
inline void Eccentricity(float a, float b [])
       int m;
       float E [7];
       for (m=0 ; m<8 ; m++)
       E [m] = sqrt(pow(a,2)-pow(b[m],2))/a;
       return E;
int main()
    //Declaring Variables
    float a=0, E=0;
    float b []= {.1, .2, .3, .4, .5, .6, .7, .8, .9};
    int l;
    cout << "This program calculates the eccentricity of a figure based on its semimajor axis for a set of likely semiminor axis" << endl;
    cout << "What is the dimension of your semimajor axis?" << endl;
    cin >> a;
    //List of possible b values
    for (l=0 ; l<8 ; l++)
        b [l] = b[l]*a;
    Eccentricity(a, b);
    //Displaying Results
    cout << "Your list of most likely eccentricities is as follows:\n" << endl;
    //cout << "{" << E[1]<<", "<<E[2]<<", "<<E[3]<<", "<<E[4]<<", "<<E[5]<<", "<<E[6]<<", "<<E[7]<<", "<<E[8]<<"}"<< endl;
    cout << E;
    system ("pause");
    return 0;
8 Years
Discussion Span
Last Post by Ancient Dragon

I always just use cin.get() because it doesn't need a variable.

This function should not beclared as inline because the compiler will likely ignore that request. inline code is normally reserved for one or two line functions, and compilers do not have to honor it at all.

float* Eccentricity(float a, float b [])
      const int MaxSize = 7;
       int m;
       float* E = new float[MaxSize];
       for (m=0 ; m < MaxSize; m++)
            E [m] = sqrt(pow(a,2)-pow(b[m],2))/a;
       return E;

Works great!
Why did you add the * after float?
What does that do?

Thanks for your help with this.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.