Dynamis array with a pointer?

Not sure how to start this?
Write a program that uses a dynamic array that contains 5 items of double values. The size of the array is entered when the program is run. Also the 5 values must be entered. These tasks are done in the main () function. Then write a function to display the 5 values. The function must have a pointer variable as a parameter. The function is called from the main ().
Last edited on
What don't you understand? I'd start with something like:
1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>

int main()
{
    printf("%s ", "Please enter the array size: ");

    ... The rest of your code here.


    return 0;
}
Is this all the question is asking for?

#include<iostream>
#include<string>

using namespace std;

void print(double* e, int size)
{
if(e == nullptr) return;

for(int i=0;i<size;i++)
cout<< e[i] ;
}

int main()
{
double* arr;
int size;

cout<<"insert size";
cin>>size;

arr = new double[size] ;
for(int i=0;i<size;i++)
{cout<<"insert val";
cin>> arr[i] ;
}

print(arr, size) ;
delete[] arr ;
return 0;
}
Topic archived. No new replies allowed.