473,412 Members | 4,127 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,412 software developers and data experts.

How to calculate weighted average

2
Weihted Average

Write a C program to calculate and print the weighted average of a list of N
floating point number, using the formula

Xave = F1X1 + F2X2+...+ FnXn

where the F's are fractional weighting factors,

i.e. 0<=F1<1, and F1+F2+...+Fn=1

For example: F1=0.1 F2=0.2 F3=0.3 F4=0.4 for n=4 and the sum=1.0

(a) Assume that N=4, and that the N numbers are already available in an array.
Use as input the following array: float X[4]={1.2,2.4,3.6,4.8};

(b) Prompt the user to enter the four weights from the keyboard. the program
should print an error messaage if the weights are out of range.

(c) For the result, the program should print the data, weights and the weighted
average.
Sep 30 '06 #1
1 20920
D_C
293 100+
Expand|Select|Wrap|Line Numbers
  1. for(i = 0, i < 4, i++)
  2. {
  3.   do
  4.   {
  5.     // get floating point number input
  6.   }  while // input is not within weight range
  7.   F[i] = input;
  8.   sum += input;
  9. }
  10. if(sum != 1.0)
  11.   // throw a fit
  12. else
  13. {
  14.   for(i = 0; i < 4, i++)
  15.     xAve += (F[i]*X[i]);
  16.   xAve /= 4;
  17.   // output xAve
  18. }
Sep 30 '06 #2

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

Similar topics

0
by: Rolan | last post by:
I know what I want to do regarding the average cost for inventory, but need some assistance to sort out some of the details to finalize an inventory table and query. Essentially, the information is...
2
by: Steve | last post by:
Hi all How would I find out the average date when given a bunch of dates? For example, I want to find the average length in time from the following dates:...
4
by: gaga | last post by:
hi guys, a part of my program requires me to calculate an average of items that are sold. the easiest way to do that would be writing a function, but im having trouble making up the parameters. if...
1
by: Sedigh | last post by:
Hi Everybody, I need to write a macro on my Excel sheet to calculate the average of cells for me. This is the code I have written but the average function is not working. Can you please let me...
3
by: Salad | last post by:
http://www.mathwords.com/w/weighted_average.htm At the above link gives an example of a weighted average. It uses the following example: Grades are often computed using a weighted average....
3
by: paeh | last post by:
hello..can anyone help me. I am beginner in programming. I need to make a system that can calculate moving average. my system process will be executed according to certain schedule such as daily,...
7
by: jamesnkk | last post by:
Hi, Although this question may not directly link to Access, but I think it a common question to those developer.so hope you could suggest a solution. How do I get the average cost for Item sold,...
0
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars...
0
by: edmund_xue | last post by:
Hello There, I was just working on a project of creating a database for a relative that have alots of clients. His company managed the shares portfolio of clients and he requires the buy price...
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?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.