473,386 Members | 1,673 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,386 software developers and data experts.

function help

could someone help with my average and sort functions in this program



[code]#include <iostream.h>


//funtion prototypes
int FindLowNum(int [], int );
int FindHighNum(int [], int);
int average(int[] , int , double );
void sorting(int [], int);

//main function
void main()
{

int A[10];
int i;
double avg;

cout << "Enter Numbers Please:\n";

for (int i=0;i<10;i++)
{
cin>>A[i];
}


for (i=0;i<10;i++)
cout<< A[i]<<' '<<endl;


cout << "the lowest value is :"<<FindLowNum(A, i)<<endl;

cout << "the highest value is :"<<FindHighNum(A, i);

cout << "the average value is :"<<average (avg);


cout<< A[i]<<' '<< sorting (A, size);

}


//function to find the lowest number
int FindLowNum(int array[], int size)
{
int lowest_so_far = array[0];
for (int i=1; i<size; i++)
{
if (array[i]<lowest_so_far)
lowest_so_far = array[i];
}
return lowest_so_far;

}

//funtion to find the highest number
int FindHighNum(int array[], int size)
{
int highest_so_far = array[0];
for (int i=1; i<size; i++)
{
if (array[i]>highest_so_far)
highest_so_far = array[i];
}
return highest_so_far;

}

//function to return the average
int average(int num[], int size, double avg)
{
for(int i=0; i<size; i++)
{
avg = (avg + num[i]);
}
avg = avg / size;


return avg;
}


//function to sort numbers
void sorting(int num[], int size)


int higher=0;
int highest=0;


for(i = 1; i <= size, i++)
{


if(num[] > highest)
highest = num[];
else if (num[] >= higher && num[] < highest)
higher = num;

size += 1;
}
[code]
Oct 5 '06 #1
1 2316
r035198x
13,262 8TB
What is the third parameter for in the average function? The function should be something like this
Expand|Select|Wrap|Line Numbers
  1. int average(int num[], int size) {
  2.        int sum = 0; 
  3.        for(int i=0; i<size; i++) {
  4.            sum = sum + num[i];
  5.         }
  6.        avg = sum / (double)size;
  7.        return avg;
  8. }
  9.  
your sort function is a mess. You need to look at a sorting tutorial
Oct 5 '06 #2

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

Similar topics

9
by: JP SIngh | last post by:
Hi All I am trying to write a recursive function to list the managers and his employees in a tree like sctructure Manager 1 Emp1 Emp1.1 Emp 1.2 Emp 2
3
by: | last post by:
Hello All, this is my first post. OK - The goal is to display the following (note: substitute 1' ' for 2'*') by using 3 recursive functions. 0123454321001234543210 **012343210012343210**...
2
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
1
by: Robert | last post by:
Vb.Net Make dll that contain one function. Help Please. I would like to call a function from different applications. I think i have to make a dll. I have Visual Basic.net 2003 Standard...
2
by: Goldie | last post by:
Can some please look at this function and maybe help me with why it's not doing as it's told... :) It's basicall meant to check to see if that field returned from database actually has any data...
2
by: TC | last post by:
IE only (V6). First, I know very little JS and our resident expert is short on time, so I come to you for help. I have a dynamic CGI script (written in Progress) that generates the following...
1
by: Abersparky | last post by:
Can someone help me with the mail() function??? The below is just to get myself going but I can't seem to get it working... is there something else I should be doing? I checked phpinfo() and the...
3
by: Lewe22 | last post by:
This is a function i have written to align a series of addresses for printing labels. However, for some reason the post code (A8) is not being moved up with the other address lines. I can't for...
5
by: turtle | last post by:
Background: I have a table of fields each field representing a month (Jan, Feb, Mar...). These are not a date field but more of a bucket to hold labor actuals. Along with the months their is...
0
by: kang jia | last post by:
hi currently i am doing this search function for car booking website. it can search through either car seats or CarModel. it seems it able to do search function, however i small problem occurs to...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.