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; }
3 Antworten
+ 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.
+ 2
thank you so much!