•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 370,597 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,012 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 2115 | Replies: 1
![]() |
•
•
Join Date: Sep 2005
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
I've had a terrible time with this program. I don't really understand it that much, but have been working on it for about 4 hours so far. One of the problems I'm having is that it keeps saying that local function definitions are illegal. Here's the program so far.
Input:
An integer array of ten numbers: 20,17,9,29,19,9,19,20,20,19
Compile-time array with initialization list of numbers.
NOTE: In main() function
Processing:
Function: computeAverage(const int[], const int):int
countLessThan(const int[], const int, const int):int
Output:
Function: display(const int, const int):void
Display as shown in sample output.
*/
<< moderator edit: added code tags:
Input:
An integer array of ten numbers: 20,17,9,29,19,9,19,20,20,19
Compile-time array with initialization list of numbers.
NOTE: In main() function
Processing:
Function: computeAverage(const int[], const int):int
countLessThan(const int[], const int, const int):int
Output:
Function: display(const int, const int):void
Display as shown in sample output.
*/
#include <iostream>
using namespace std;
void main(void)
{
// constants
const int SIZE = 10;
// function prototype(s)
// return by value is used
int computeAverage(const int[], const int);
int countLessThan(const int[], const int, const int);
void display(const int, const int);
// local data
int intAverage = 0;
int count = 0;
// data declaration(s) & initialization(s)
// array data: use data from sample output above
// TODO: declare & initialize array of ten integers
int numbers[] = {20,17,9,29,19,9,19,20,20,19};
// start the program
cout << "*** start of 276Arrays_Ex02.cpp program ***" << endl;
cout << endl;
// Compute & return integer average of the array
// TODO: call computeAverage()function,
// which returns average of numbers
intAverage = computeAverage(numbers, SIZE);
// Compute & return count of array values less than integer average
// TODO: call countLessThan() function,
// which returns count of numbers less than the average
count = countLessThan(numbers, intAverage, SIZE);
// display the required output
// TODO: call display function,
// passing integer average & count of numbers less than average
display( intAverage, count);
// terminate the program
cout << endl;
cout << endl;
cout << "*** end of 276Arrays_Ex02.cpp program ***" << endl << endl;
cin.get();
return;
} // end main()
//--------------------------------------------------------------------//
// Function Name: display(const int, const int):void
// Purpose: to display integer average & count less than average
// Values received: integer average, count
// Values returned: <none>
// Notes:
// display label "Average Integer Score: "
// display integer average
// display label "Count of Integers Less Than Average: "
// display count
//--------------------------------------------------------------------//
// TODO: code the display function
void display(const int num[], const int size)
{
// display labels and data
// TODO: code the computeAverage function
int computeAverage(int num[], int size)
{
// local variables (if needed)
int sum;
// compute sum
sum += numbers;
// compute integer average
for(int index = 0; index < size; index++)
sum += num[index];
average = sum / size;
// return integer average
return intAverage;
}
// TODO: code the countLessThan function
int countLessThan(const int numbers[],
const int intAverage,
const int SIZE)
{
// local variables (if needed)
int count;
// count number of values less than average
// return count
return count;
}[code][/code] >> Last edited by Dave Sinkula : Nov 3rd, 2005 at 9:28 pm.
•
•
•
•
Originally Posted by wdowell84
One of the problems I'm having is that it keeps saying that local function definitions are illegal. Here's the program so far.
// TODO: code the display function
void display(const int num[], const int size)
{
// display labels and data
// TODO: code the computeAverage function
int computeAverage(int num[], int size)
{![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
- How to populate an array? from a FILE (C)
- Storing A Long Array of bytes in an XML file. (C#)
- Insertion Sort Problem (C++)
- constructor with an array as an argument (C++)
- erge and Heap...which is really faster (C++)
- Sorting Algorithms using Time (C++)
- template issues - need expert debugger! (C++)
- Resizing of an array. (C++)
- I need help (C++)
Other Threads in the C++ Forum
- Previous Thread: Student requesting help - Please!
- Next Thread: parsing conf file in c++



Linear Mode