I have lots of questions about c++ that are really confusing me
   
I started learning c++ about 3 weeks ago after 2 years of java. It seems so different but im getting there. my lecturer is a lovely guy but any time i ask a question as to why something is that way or this way.  he just responds "because it is".

Theres lots of comments in the code below with a few random questions, but the main problem is im getting two build errors, one says the arraytotal has not been initialized (even though i found a value for it) and the other says an external reference in main.

would anyone mind reading the code and answering a few comments within, and maybe the overall problem im having?



  #include<string>
    #include<fstream>
    #include<ostream>


    using namespace std;

     //double decimals[5] ={2,4,6,8,10};
	
      const int arraySize = 5;
    // does an arraySize have to be const always? is it so it doesnt channge after the array has been created?


     //double decimals[arraySize];

    /*
     this array is being created in the function averageN() but why?
     cant i just create it up top and reference it in?
     */


    // why do you have to write the name of the function up here before you even create it?
    double averageN();
	

     int main()
     {
     	averageN();
     	return 0;
     }

     // why does the array have to be created here?
     double averageN(double decimals[arraySize])
         {

	double average;
	double arrayTotal;
	for (int i = 0; i<5;i++)
	{
		// fills with random numbers from 0 - 10
		decimals[i] = (0+(rand()%10));
	}
	
	// find the total of all the elements in the array
	for (int i = 0; i < arraySize;i++)
	{
		double currentElement = decimals[i];
		arrayTotal = (currentElement+arrayTotal);
		//arrayTotal +=decimals[i]) ;
	}
	// return the average
	average = (arrayTotal/arraySize);
	return 0.0;
     }
I have lots of questions about c++ that are really confusing me
===

   
I started learning c++ about 3 weeks ago after 2 years of java. It seems so different but im getting there. my lecturer is a lovely guy but any time i ask a question as to why something is that way or this way.  he just responds "because it is".

Theres lots of comments in the code below with a few random questions, but the main problem is im getting two build errors, one says the arraytotal has not been initialized (even though i found a value for it) and the other says an external reference in main.

would anyone mind reading the code and answering a few comments within, and maybe the overall problem im having?



  #include<string>
    #include<fstream>
    #include<ostream>


    using namespace std;

     //double decimals[5] ={2,4,6,8,10};
	
      const int arraySize = 5;
    // does an arraySize have to be const always? is it so it doesnt channge after the array has been created?


     //double decimals[arraySize];

    /*
     this array is being created in the function averageN() but why?
     cant i just create it up top and reference it in?
     */


    // why do you have to write the name of the function up here before you even create it?
    double averageN();
	

     int main()
     {
     	averageN();
     	return 0;
     }

     // why does the array have to be created here?
     double averageN(double decimals[arraySize])
         {

	double average;
	double arrayTotal;
	for (int i = 0; i<5;i++)
	{
		// fills with random numbers from 0 - 10
		decimals[i] = (0+(rand()%10));
	}
	
	// find the total of all the elements in the array
	for (int i = 0; i < arraySize;i++)
	{
		double currentElement = decimals[i];
		arrayTotal = (currentElement+arrayTotal);
		//arrayTotal +=decimals[i]) ;
	}
	// return the average
	average = (arrayTotal/arraySize);
	return 0.0;
     }