473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Specific function must return a value?

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.

1 1729
weaknessforcats
9,208 Expert Mod 8TB
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

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

Similar topics

3
by: Jonas | last post by:
Dear members, How can I use a function return value in a regexpr? $tmp=~s/mysearch/myfunction($1)/; sub myfunction { return $v; }
1
by: Tropos | last post by:
Query: Will a MutexGuard object release before a function return value is copied? Consider the C++ code: class MutexGuard //A familiar sort of class for making mutexes exception-safe { . ....
4
by: wongjoekmeu | last post by:
Hello All, I know that when you pass an argument to a function (if you want let the function be able to change the value) then you can choose to pass the argument by reference or a pointer to...
4
by: bluedolphin | last post by:
This is my first function in Visual and I'm having a simple syntax syntax issue that I'm hoping someone can help correct for me. I have a function Public Function...
8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
7
by: chellappa | last post by:
hi this program return value automatically ... how it is possible ..i am not return any value... but i return correct values i am using Linux -gcc complier please tell me what is this main() {...
11
by: randomtalk | last post by:
hi, i have the following recursive function (simplified to demonstrate the problem): >>> def reTest(bool): .... result = .... if not bool: .... reTest(True) .... else: .... print...
8
by: bdobby | last post by:
Hi. I am relatively new to js, but I did think I was starting to get the hang of it. Then this happened... I have a form with an onsubmit event handler: <form id="uploadForm" method="post"...
4
by: pradeep | last post by:
Hello friends ~ We know that a C function will return a 32-bit value from a function in %eax and a 64-bit value in %edx:%eax. But what about larger return types, for example large structs? The...
6
by: kurt.krueckeberg | last post by:
Can someone explain why this line $bool = isset($_POST) && !empty(trim($_POST)); causes the error message "Can't use function return value in write context". trim() returns a string. I test if it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.