Stuck on 33.2 challenge, dynamic memory | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Stuck on 33.2 challenge, dynamic memory

Hey peeps, I understand how you can input the array size (n) and then input each value, but I’m having difficulty linking that to the given code in the challenge- which selects the maximum value of the values. This code is as far as I can get without my brain hurting 🤪 #include <iostream> using namespace std; int main() { int n; int *ptr; cin>>n; ptr = new int[n]; for(int i=0;i<n;i++) { cin>>ptr[i]; int max = nums[0]; for(int i=0; i<n; i++) { if(nums[i]>max) max = nums[i]; } cout << max; } return 0; }

28th Feb 2021, 2:04 AM
Millü
Millü - avatar
2 Answers
+ 3
(1) You're nesting for loops, which I don't think you've noticed. for(int i=0;i<n;i++) { cin>>ptr[i]; } <- Missing And there is an extra brackets before return 0. (2) nums[] does not exist, ptr[] does. (3) You did not delete ptr at the end of the code.
28th Feb 2021, 2:22 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 2
thank you so much!
28th Feb 2021, 2:46 AM
Millü
Millü - avatar