HELP WITH EASY HOMEWORK CODE - [Dynamic Memory Allocation] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

HELP WITH EASY HOMEWORK CODE - [Dynamic Memory Allocation]

Hello, I am taking C++ beginner class and I can't get to do this. The instruction is: 1. cin >> size of array 2. cin >> number (in array) 3. cout << "Number of values grater than the average is " << ( HINT : int* list = new list[size] ) And the answer should be this. Enter array size: 3 Enter number: 1 Enter number: 5 Enter number: 7 The number of values greater than the average is 2 Please, some help :(( I don't know how to get the average or how to make the "enter a number" repeat when using dynamic memory allocation.

21st Nov 2019, 9:39 AM
Dosei
2 Answers
+ 1
Ok, thank you very much for your help - swim - ! I will keep working on that!
25th Nov 2019, 1:37 AM
Dosei
0
I'm sorry, I know what you mean. Here I tried to do this code: #include <iostream> using namespace std; void aboveAvg(); int main() { int size, i; double sum = 0; double Avg; cout << "Enter array number: "; cin >> size; int* list = new int[size]; for (i = 0; i < size; ++i) { cout << i + 1 << "Enter a number: "; cin >> list[i]; sum += list[i]; } Avg = sum / size; cout << "The numbers greater than average are: " << aboveAvg() << endl; return 0; } void aboveAvg(double Avg, int *list){ if (*list > Avg) { cout << *list << " " << endl; } } ------ I only have one error which says " no operator << matches this operands" before aboveAvg << endl; I need some guidance with that. Also, if someone could check if my void code is correct I would really appreciate it, I still find it difficult to understand how to call array and its elements into a void function.
24th Nov 2019, 5:28 PM
Dosei