going through a c++ course and was asked to create a simple program to average values in a user array
i figured id go the extra mile and learn to mess with a few additional types.
I searched online for a fix for the non variable arrays in c, and i know this is where shit hits the fan
//manually allocate the space to the array
int** MyArray = new int* [Length_Of_Array]; // i changed it to float to suit my program
For my error's im getting ERROR IMAGE
Is there a better alternative to this (sticking to arrays as opposed to vectors) ?
MY FULL CODE
#include <iostream>
using namespace std;
//function declare
float Avg(float Array, int Length);
//Variable declare
int Length_Of_Array;
int main()
{
//Declarations
float Result{};
//User defines size of the array
cout << "Please enter the length of your array (Min 5) ";
cin >> Length_Of_Array;
//User Enters x elements into array
cout << "Please enter" << Length_Of_Array << " Digits into the array " << endl;
//manually allocate the space to the array
float** MyArray = new float* [Length_Of_Array];
//Function use
Result = Avg(MyArray, Length_Of_Array);
//Result
cout << "THE AVERAGE OF YOUR ARRAY IS " << Result << endl;
}
float Avg(float** Array, int length) {
int sum{};
//Stores, enters and calculates user enters elements into array
for (int i = 0; i < length; i++) {
cin >> Array[i];
sum += Array[i];
}
return (sum /length);
}