Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this code so far for in my C++ program in codeblocks. I'm having problems retrieving the values of myArray and summing them in

I have this code so far for in my C++ program in codeblocks. I'm having problems retrieving the values of myArray and summing them in the avgFunc(). I need to be able to sum the values from myFunc in avgFunc and print them out in the console.

#include #include #include #include #include #include using std::fixed; using std::setprecision; using std::cout; using std::cin; using std::endl;

// Function declarations and definitions

/* Function of given size and populated with random values between 0 - 100 */ void myFunc(int* array, const unsigned int size){ srand(time(nullptr)); cout << "["; for(int i = 0; i < size; ++i) { array[i] = rand() % 100; cout << " " << array[i]; } cout << " ]" << endl; }

/* Function to calculate the average of the array should take as arguments the array and its size */

void avgFunc(int* array, const unsigned int size){ double sum = 0; int* myArray; unsigned int mySize;

for(int i = 0; i < size; ++i){ sum += myArray[i]; cout << " " << sum << endl;

} cout << fixed << setprecision(2) << sum << endl; }

int main() {

int* myArray; unsigned int mySize;

cout << "Enter array size: "; cin >> mySize; int* theSize = new int[mySize];

myFunc(myArray, mySize);

avgFunc(myArray, mySize);

delete[] myArray;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions

Question

Derive expressions for the rates of forward and reverse reactions?

Answered: 1 week ago

Question

Write an expression for half-life and explain it with a diagram.

Answered: 1 week ago

Question

What do you mean by underwriting of shares ?

Answered: 1 week ago

Question

Define "Rights Issue".

Answered: 1 week ago