By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Specific function must return a value?

P: 1
Hi, I'm new to C++ programming and this program basically needs to populate an array with integers from the user and display the array as part of a string. The catch is that I have to use specific functions given to me. However, one of them(populate_array() ) keeps bothering me to return a value but I don't know how to fix it. Any help would be much appreciated! Also, I have more functions to add later but my code for now is:

#include <iostream>
const int ArSize = 6;

void display_array(const double ar[], int n);
int populate_array(double ar[], int limit);

int main()
{
using namespace 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)
{
using namespace std;

for (int i = 0; i < 6; i++)
{
cout << "Please enter an integar: " << endl;
cin >> ar[i];
populate_array(ar, 6);

}

void display_array(const double ar[], int n);
{
cout << "The elements of the array are: " << display_array << endl;
}

}
Oct 18 '15 #1

✓ answered by weaknessforcats

populate_array returns an int:

Expand|Select|Wrap|Line Numbers
  1. int populate_array(double ar[], int limit)
  2.  {
  3.  using namespace std;
  4. etc...
but there is no return statement in the code. If you were given this function, then you got code that can't compile.

Either change the function to:

Expand|Select|Wrap|Line Numbers
  1. void populate_array(double ar[], int limit)
  2.  {
  3.  using namespace std;
  4. etc...
or put a return statement at the end of the function to return some value. Maybe a 1 to signify that the funveiton worked.

Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
populate_array returns an int:

Expand|Select|Wrap|Line Numbers
  1. int populate_array(double ar[], int limit)
  2.  {
  3.  using namespace std;
  4. etc...
but there is no return statement in the code. If you were given this function, then you got code that can't compile.

Either change the function to:

Expand|Select|Wrap|Line Numbers
  1. void populate_array(double ar[], int limit)
  2.  {
  3.  using namespace std;
  4. etc...
or put a return statement at the end of the function to return some value. Maybe a 1 to signify that the funveiton worked.
Oct 19 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.