c++ - How do I return my dynamically allocated array? -
So for my problem I need a dynamically allocated array that can be created in the main function and any other function. The problem I am facing is that I need to use that function in other functions and my array has no value when I put it in my function (or at least this case). The code is:
#include & lt; Iostream & gt; # Include & lt; iomanip & gt; using namespace std; // prototype int getNumber (); Zero getMovieData (int * ptrToArray, int arraySize); Zero Type (integer * ptrToArray, int arraySize); Double getAverage (integer * ptrToArray, int arraySize); Zero print (integer * ptrToArray, int arraySize); Int main () {int stuNum = 0; Int * stuArray; Steware = new int [stuum]; GetMovieData (Stuyere, Stnam); Cout & lt; & Lt; "--- Here is the data you entered" & lt; & Lt; Endl; Print (steware, stoom); Sort (Stuyere, Stnam); Cout & lt; & Lt; "--- Here is the data that you sort" - & lt; & Lt; Endl; Print (steware, stoom); Cout & lt; & Lt; Fixed & lt; & Lt; Setprecision (2); Cout & lt; & Lt; "Average of your survey here" & lt; & Lt; GetAverage (Stuyere, Stumen) & lt; & Lt; Endl; System ("pause"); Return 0; } Int getNumber () {int userNum; Cin & gt; & Gt; UserNum; While (username & lt; = 0) {cout & lt; & Lt; "Error number must be greater than zero." & Lt; & Lt; Endl; Cin & gt; & Gt; UserNum; } Return User Number; } Zero getMovieData (int * ptrToArray, int arraySize) {cout & lt; & Lt; "Enter the number of students being surveyed:"; ArraySize = getNumber (); For (int i = 0; i & lt; array; i ++) {cout & lt; & Lt; "Enter the movie student watched" & lt; & Lt; I + 1 & lt; & Lt; ":"; PtrToArray [i] = getNumber (); } Return; } (For zero; i ++;) (for (int j = 0; j & lt; girus siege - 1; j ++) {if (ptrToArray [j] & gt; ptrToArray [j + 1]) {Int temp = ptrToArray [j]; PtrToArray [j] = ptrToArray [j + 1]; PtrToArray [j + 1] = temp;}}}} Dual gain (integer * ptrToArray, int arraySize) {int total = 0 (For int i = 0; i & lt; arrays; i ++) {total = total + ptaraoRa [i]; total return;} zero print (integer * ptrToArray, int arraySize) {for (int i = 0; i & lt; Array size; i ++) {cout & lt; PtrToArray [i] & lt; "\ T";} cout
You are allocating an array with zero elements Not change in a positive number value Stuam, which is represented by a number of the required number.
Comments
Post a Comment