473,396 Members | 2,003 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,396 software developers and data experts.

find average of 10 numbers passed to an array using function. the array should be con

1
find the average of 10 numbers to an array using function .the array should be controlled by while loop?

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. float sum(float x[],int size);
  3.     main()
  4. {
  5.    float a[10];
  6. int n=10;
  7. while (n<10)
  8.  
  9. {
  10.    cin>>a[n];
  11. n++;
  12. }
  13. cout<<"avg = "sum (a+n)/n;
  14. }
  15. floatsum(floatx{},int size)
  16. {
  17. float total=o;
  18. for(int i=0,i<size,i++);
  19. {
  20. total=total +x[i];
  21. }
  22. return total;
  23. }
Jun 20 '12 #1
2 4223
weaknessforcats
9,208 Expert Mod 8TB
What is your question exactly?

Please post your code after it compiles.

It looks like you are on the right track.
Jun 20 '12 #2
whodgson
542 512MB
The include file is <iostream>
main() should return an int e.g. int main()
The prototype sum() function is different to the sum ()function definition.
total is initialized with 'o' not '0'
Your while loop can't loop as n is assigned 10 when the loop condition is n<10.
The float x[] should not have {} brackets
By surrounding your code with code tags others can more easily read it.
Jun 22 '12 #3

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

Similar topics

5
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
13
by: Martin Altschwager | last post by:
Hi, I desperately need some help with what I assume to be a minor problem that I just can't solve. I'm writing a page where on mouseover a link, an image needs to be displayed and some text,...
1
by: john | last post by:
Relatively new to C coding, so any help would greatly be appreciated. I'm having problems try to return my string array from my parsing function. When I do a printf I am getting the correct value...
11
by: Sontu | last post by:
Consider the following code: int main(void) { char buffer; func(buffer); } void func(char *bufpas) {
1
by: Julia | last post by:
Hi, I have been asked this before but I think that I didn't explain myself well I am using exception and logging and I would like to log the parameters which was passed to the function...
1
by: Zarwadi | last post by:
Hi i have 2 array's one is like this (123, 123, 123) the other (123, 435, 123, 564, 123, 780, 453, 123) I need to know how to use the first array to find the matching data and it;s postion in...
1
by: procris99 | last post by:
I'm having ALOT of trouble understanding this (C++)..and i don't think i'm even close to getting this right. Please help. The problem reads as follows: Use a one dimensional array to solve. A...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
2
by: Josiah Vergonio | last post by:
#include<iostream> using namespace std; class Test { public: void search(int arr) { int count=0; int size=(sizeof arr/sizeof arr); cout << "In search function, size = " <<size<<endl;
3
by: Brian Connelly | last post by:
Okay, I have two files one is the HTML where the user inputs a name, and clicks Add. The add button calls on a JavaScript Function created that is suppose to put sort the names. Adding One or more...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.