Hi, I'm pretty new to C++ language and I have a question about this code as it has been driving me crazy.
I have to use specific functions for an assignment, however when I use the function populate_array (), an error keeps popping up that says that it must return a value. I have tried messing around with it, but i'm at a loss.
My code so far is seen below:
I need the program to populate the array with integers entered by the user and then display the array later as part of a string for now, I still have to add more functions later. Any help would be greatly appreciated!
#include <iostream>
constint ArSize = 6;
void display_array(constdouble ar[], int n);
int populate_array(double ar[], int limit);
int main()
{
usingnamespace std;
cout << "This program takes integars and puts them into an array. They are later manipulated." << endl;
int array[6];
}
int populate_array(double ar[], int limit)
{
usingnamespace std;
for (int i = 0; i < 6; i++)
{
cout << "Please enter an integar: " << endl;
cin >> ar[i];
populate_array(ar, 6);
}
void display_array(constdouble ar[], int n);
{
cout << "The elements of the array are: " << display_array << endl;
}
}
You told your compiler that populate_array returns an int, yet you don't have a single return statement in your function body. Either mark the return type void or return a value in all cases.