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

how to find the average of thee groups of values?

3
HELLO,

Any idea how to compute the averages for 6 values that have been computed from a for loop,

I mean once the for loop finishes it prints me six different values classified into 3 groups as shown down:

group1 has value1
groupe2 has value2, value3, value3
group3 has value5, value6

I want to find the average for each group.

considering the number of values in each group might change.
this is the code for finding the values:


Expand|Select|Wrap|Line Numbers
  1.  
  2. for (int i=0; i<n; i++)
  3.     {
  4.         if (value < 25)
  5.         {
  6.             group1++;
  7.             class = "group1";
  8.  
  9.         }
  10.         else if (value > 50)
  11.         {
  12.             groupe3++;
  13.             class = "groupe3";
  14.         }
  15.         else 
  16.         {
  17.             group2++;
  18.             class = "group2";
  19.         }
  20.  
  21.  
the final result like this:
cout<<"average of group1 is"<<
cout<<"average of group2 is"<<
cout<<"average of group3 is"<<

:) ?
Aug 14 '14 #1
5 1141
weaknessforcats
9,208 Expert Mod 8TB
The average is the sum of the elements in the group divided by the number of elements in the group.

I see you count the number of elements in the group but I do not see where you add up the values of the elements. You need to do that so you can divide this sum by the number of elements in the group.

You don't need the class literal at all:

Expand|Select|Wrap|Line Numbers
  1. cout << "Group 1 average= " << sumgroup1/group1 << endl;
Aug 14 '14 #2
neesaY
3
the problem is that the program gets the value from a file and it did classifies the values into groups according to some characteristics they had,
so your way required me to know each value in each group! and I can't do that.

what I want is the program to classify the values into groups and then find the averages.
Aug 14 '14 #3
weaknessforcats
9,208 Expert Mod 8TB
You know each value in each group.

This code:
Expand|Select|Wrap|Line Numbers
  1. if (value < 25)
  2.          {
  3.              group1++;
  4.              class = "group1";
  5. etc.... 
  6.  
identifies value as a member of group 1. So each time you get here add value to a total value for group1. It's the class you don't need.
Aug 14 '14 #4
neesaY
3
hmmm I got the values,
for the classes it is required for the final output of the project, I need to classify the values as ( fast , medium , slow)
the same as I used up like (group1, group2, group3)
the values are actually speeds, and I need to find the average of the fast speeds, medium speeds and slow speeds!

also the values came from an equation already computed the the original project.

the program do this: get numbers from file then use them in an equation then find the speeds (values)
.
Aug 14 '14 #5
weaknessforcats
9,208 Expert Mod 8TB
As soon as you start classifying values a FAST, MEDIUM, or SLOW, I start thinking about a struct:

Expand|Select|Wrap|Line Numbers
  1. enum group {FAST, MEDIUM, SLOW};
  2.  
  3. struct Speed
  4. {
  5.    int value:
  6.    enum group;  
  7. };
Each time you read a value from the disc file you could create a Speed variable.

Expand|Select|Wrap|Line Numbers
  1. Speed* ptr = malloc(sizeof Speed);
  2.  
Put the value in the value member:

Expand|Select|Wrap|Line Numbers
  1. ptr->value = disc value;
  2.  
  3.  
Then use the logic to classify the value:

Expand|Select|Wrap|Line Numbers
  1. for (int i=0; i<n; i++)
  2.     {
  3.         if (value < 25)
  4.         {
  5.             ptr->group = SLOW;
  6.         }
  7.         else if (value > 50)
  8.         {
  9.             ptr->group = MEDIUM;        }
  10. etc...
  11.  
  12.  
You could keep these Speed variables in an array or a linked list. When you have processed the disc values, you will have a little database. Now you can scan the database and now you can count the SLOW, MEDIUM and FAST values, add them up, calculate averages, etc.
Aug 14 '14 #6

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

Similar topics

0
by: Mad Scientist Jr | last post by:
a search for "microsoft .net" should bring up a list of microsoft.public.dotnet groups, but what does it list first? comp.os.linux.advocacy.... what the heck? comon google, live up to your name
1
by: Meena Lalwani | last post by:
Hi All, I am working on the performance measurement for my dot net application. There are 5000 to 10000 users who logged in with my application. I am able to find out which user logged in ,...
3
by: Gomathi | last post by:
hi all, In ASP.Net , i'm using a dataset. I want to find whether it has any values or not. How to do that? Thanks in advance. Regards, Gomathi
0
by: jmk | last post by:
Hi, I am currently writing a vb .net 2003 program that updates values in our AD with values stored elsewhere. Getting a list and updating values works fine using the DirectoryServices. ...
5
by: NoOoR | last post by:
I want to write a program that read n numbers and perform some mathematical tasks on them. The task available for the user is as follow : 1- Finding the average 2- Find the maximum...
10
by: Toby Gallier | last post by:
Hello! I have a form that is calculating averages as follows: " =(NZ()+Nz()+Nz())/3 " However I need to now adjust for null values , so for example if value2 is null I would then need to...
2
reginaldmerritt
by: reginaldmerritt | last post by:
I have a table (tbBookings) which holds three important bits of information about a Shift or Job. These are (dateofshift) (typeofshift) (staffbooked). On a form i want to have an AfterUpdate event...
14
by: lee | last post by:
hi, i have a dictionary as follows : kev : {'phno': , 'email': , 'name': , 'address': } if user is enters the 3rd item of key phno, ie "dfsdf" in my dict, how can i find it is the third item...
8
by: gigonomics | last post by:
Hi all, I hope someone can help me out. I need to return the best available seats subject to the constraint that the seats are side by side (or return X consecutive records from a table column...
6
by: jeddiki | last post by:
I am writing a little script that will improve authors writing skills by finding repeated phrases in the text. The text of a chapter will average about 10,000 words, however, I could reduce the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.